php command line maximum process

I run many times PHP script in one minute in my server using command line. but i want to add some maximum for it.

this script not must be run each time more than 10 process for PHP.

#1 php -r myhardandlongprocess.php
#2 php -r myhardandlongprocess.php
..
#10 php -r myhardandlongprocess.php

any standard way for this?

Upvotes: 2

Views: 335

Answers (1)

fdomig
fdomig

Reputation: 4457

You could use the exec() command to do that:

$output;
$return;
exec('ps |grep ' . __FILE__ . ' |wc -l', $output, $return);

echo ((int) trim($output[0])) - 1;

EDIT: Changed to exec() since system() outputs everything directly.

Upvotes: 1

Related Questions