3

Is there some way to get the CPU (ideally also memory) usage of a script?

Pretty much everything I found so far was about general CPU usage - however what I need is just a CPU usage of my PHP script, so that other running processes don't affect the results (which is the case when I simply calculate the time or get the total CPU usage at a given time).

What I need would be some number of instructions, time of CPU time used or whatever that would allow me to compare the run time of 2 scripts.

  • I haven't tinkered or tried it myself but DirectAdmin (A package to manage servers) has an API which allows you to browse various data. Including processes and the time processes have ran. If you are able to setup a server which allows getmypid() in php I think you are one step closer to reaching your goal. I believe getmypid() retrieves the PID of the current script. You can cross reference that with the data returned from the directadmin data. http://php.net/manual/en/function.getmypid.php http://www.directadmin.com/features.php?id=1362 – Rimble Dec 09 '14 at 23:02
  • After that I'm not quite sure if you can capture all the data you need. I'm not quite sure when the PID will leave the list of active processes etc, not big on operating systems. – Rimble Dec 09 '14 at 23:04
  • Not to mention PID isn't unique and can/will be re-used. You can get memory usage from within php using [get_memory_usage](http://www.php.net/get_memory_usage). – Jonathan Kuhn Dec 09 '14 at 23:06
  • http://stackoverflow.com/questions/535020/tracking-the-script-execution-time-in-php http://www.kavoir.com/2010/09/check-how-much-memory-your-php-script-is-using-php-script-memory-usage.html – Len_D Dec 09 '14 at 23:07

0 Answers0