Rohitashv Singhal
Rohitashv Singhal

Reputation: 4557

run a php script in background

I have a php scrip, in which i have written the following code

$client = new \Predis\Client();
$client->select(4);
$client->lpush('emailid',$x['to']);


$command = "/usr/bin/php5 -f /var/www/Symfony/src/Ens/NewBundle/Controller/cron.php";

exec( "$command > /dev/null &", $arrOutput );

return $this->render('EnsNewBundle:Email:header.html.twig');

in this I have written an another php script named as cron.php. I want to run that script in background. and I want to check that is this running in background or not. how can i check that

Upvotes: 0

Views: 3067

Answers (2)

user1041440
user1041440

Reputation: 211

Maybe you could have a look to the Symfony2 Process component.

It's quite useful for running command from PHP.

Upvotes: 5

amitchhajer
amitchhajer

Reputation: 12830

You can take the output of cron in a file by > filename and check if it really runs.

Or check in process list if there is a new php process stating when you run this one.

You should also look at Codememe bundle here

Do check open source queuing systems too, they are helpful many times. Like Beanstalkd or RabbitMQ

You can push data to these queues, they can be say "filenames" and other worker takes data from the "tubes" of queues and apply say "php filename" and then picks up next data from queue.

Upvotes: 1

Related Questions