Ubuntu how to run php shell script without waiting for output

How to run php script in shell without waiting for an output allowing you to leave the script running in the background or even ending the terminal.

1. First create php script file e.g RunBashScript.php and add the following code:

<?php
exec(‘sh /[full path to bash script]/RunPhpScript.sh > /dev/null 2>&1 &’);
?>

Save the file.

2. Next create bash script e.g RunPhpScript.sh and add the following:

#!/bin/sh
/usr/bin/php -f /[full path to your actual php script]/ActualScriptToRun.php

Save that file.

3. To run your php script in the terminal type the following:

/usr/bin/php -f /[full path to bash script]/RunBashScript.php

Run “top” to see if PHP is running

To kill PHP simply run “pkill php”

Hope this helps someone!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: