how can I do that?
how do share hosts limit the CPU time for a script?
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.
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.
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.
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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With