0

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

1

2 Answers 2

5

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

It's quite useful for running command from PHP.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

6 Comments

when i m running on command line php test.php then it is giving correct answer but when i am running this command in another php file as follow: echo shell_exec('php test.php | /dev/null &'); then it is giving no answer
when you do shell_exec the process starts in background, so take some standard output from test.php to a file using shell_exec('php test.php > file'); , you don't need '&' here. And check if test.php returned successfully using echoing something at file termination, which will be stored in file
this is not giving any response
when i am running whoami directly in this exec() then its giving correct ans but when i am execution this in test,php and executing test,php in index.php then it is giving blank
is test.php made to do anything? try something like sexec("mkdir dir") in test.php and check whether it is running or not.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.