Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to monitor the CPU usage of a PHP script

Tags:

php

how can I do that?

how do share hosts limit the CPU time for a script?

like image 312
Alex Avatar asked Jan 24 '11 23:01

Alex


People also ask

How can I get CPU usage in PHP?

For getting CPU uses you can simply use getrusage() function in PHP It'll return lots of CPU uses variables that help you to determine whats sources uses too much CPU resources.

How do I see exact CPU usage in Linux?

Check CPU Usage with vmstat Command The vmstat command will display the information about system processes, memory, swap, I/O, and CPU performance. It will display the average details since the last reboot. Press CTRL+C to close the vmstat.

How do I check CPU utilization logs?

Use Task Manager to view CPU consumption If you see a single list of tasks in the Task Manager window, click the More Details arrow to show the expanded view. Click the Processes tab if it is not already selected by default. Click the CPU header at the top of the table to sort by CPU usage.


2 Answers

There isn't a native method for doing this in PHP so I would try phpSysInfo as it provides information on CPU, uptime, ethernet, SCSI, IDE, etc. http://phpsysinfo.sourceforge.net/

like image 84
niczak Avatar answered Oct 15 '22 06:10

niczak


Web hosts have several means of limiting PHP (and how much memory a child web server process can consume). Commonly, PHP is limited by the max execution time configured in php.ini (which is also set so that functions like set_time_limit() can't override it. Additionally, hosts use things ulimit to limit the amount of memory / time that any given process can consume.

If not configured to restrict PHP to individual webroots, you can open /proc/self and have access to statistics about your process. Note, you won't be able to do that, or use phpsysinfo if open_basedir is in effect.

like image 38
Tim Post Avatar answered Oct 15 '22 05:10

Tim Post