11

Why does the PHP/Apache combo do so many gettimeofday syscalls? Even though the're quick every call is a call which should be accounted for.

Just a quick strace -c -p [apache2 process id], gives the following:

Process 22294 detached
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 98.52    0.010000          51       196           poll
  1.48    0.000150           0     20752           gettimeofday
  0.00    0.000000           0        94         7 read
  0.00    0.000000           0        48           write
  0.00    0.000000           0        96        32 open
  0.00    0.000000           0        75           close
  0.00    0.000000           0         6           chdir
  0.00    0.000000           0       766           time
  0.00    0.000000           0         2           chmod
  0.00    0.000000           0        56        10 access

Those 20K calls worry me. Anyone care to shed some light on this?

4

Gettimeofday is mostly called by Apache to log entries in debug-files. Also some modules use gettimeofday. So nothing to worry about.

EDIT: I did some php source code digging and came up with the following results: Most time related php functions will use the system time. Since they use the system time, gettimeofday will be called a lot so if you want to reducte the calls, reducte your time related functions.

I have to remark though that other functions also make gettimeofday-calls. For example if you use php_session_start, this will (sometimes, depening on a few parameters like if a new session,...) make a call to php_combined_lcg which will make in his turn a call to lcg_seed if there is no seed value set to get a pseudo random number. And lcg_seed will make a gettimeofday call. Keep this in mind.

  • But what if my CLI php script also does alot of gettimeofday calls? is there something wrong with my php? (does i.e. date() or mktime() use those functions if i dont provide a timestamp as a param?) – Gekkie Apr 3 '13 at 10:06
  • Searched a bit and edited my answer – timmeyh Apr 3 '13 at 22:06
  • Thanks... I guess i just have to live with all those calls. :) – Gekkie Apr 5 '13 at 8:34
  • If you have xdebug installed, it can also be a byproduct of it. – B00MER Feb 17 '15 at 10:58
1

I have discovered that having the php module, xdebug, enabled causes strace to report several gettimeofday calls.

1

Every process that requires a timestamp calls gettimeofday, so it is difficult to know whether it is normal or not.

For example, It can be a module that creates a log, a module that checks the time... In fact, in your case, to know why there are so many gettimeofday, disable apache modules that could be responsible for calling gettimeofday. There are maybe too many writes to numerous log files located in different folders.

  • Disable the usual suspects like mod_log_debug or mod_status
  • Reload configuration of Apache
  • strace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.