PHP 8.5.0 Beta 1 available for testing

Voting

: six minus one?
(Example: nine)

The Note You're Voting On

pdc at example dot com
13 years ago
Here is how you'd use exec on a posix system to accomplish counting processes quickly.

I want to know how many processes are running with 'update.php' in the command:

ps aux|grep "[u]pdate.php"|wc -l

(the trick of using [u]pdate.php instead of update.php makes sure that the grep command itself is not matched). Be sure to use quotes in the command, or it won't work either.

So, the code:

<?php
function countProcesses($scriptName)
{
// ps aux|grep "[u]pdate.php"|wc -l
$first = substr($scriptName, 0, 1);
$rest = substr($scriptName, 1);

$name = '"['.$first.']'.$rest.'"';
$cmd = "ps aux | grep $name | wc -l";

$result = exec($cmd);

return
$result;
}
?>

<< Back to user notes page

To Top