By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,905 Members | 902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,905 IT Pros & Developers. It's quick & easy.

Execute php page automatically in the background ?

P: 43
Hi guys,

I wanna to execute a php page automatically in the background,

or execute it in shell script, and set this script to execute as a cron job.

so who knows either of the two questions :
1- execute a php page automatically in the background ?
2- execute a php page in shell script ?

anyone knows how to do this ?

thanks a million.

Tanya
Jul 12 '07 #1
Share this Question
Share on Google+
7 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Tanya.

I'm pretty sure this will work:
Expand|Select|Wrap|Line Numbers
  1. `php /path/to/file &`;
  2.  
  3. // Alternatively, try this:
  4. pclose(popen('php /path/to/file &'));
  5.  
The '&' is important. It tells the shell not to wait for the process to exit.
Jul 12 '07 #2

P: 43
Heya, Tanya.

I'm pretty sure this will work:
Expand|Select|Wrap|Line Numbers
  1. `php /path/to/file &`;
  2.  
  3. // Alternatively, try this:
  4. pclose(popen('php /path/to/file &'));
  5.  
The '&' is important. It tells the shell not to wait for the process to exit.
thanks for answering first!

I tried :
`php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &` ;
it returned :
php: command not found
I am wondering do I need to set up any config files in order to make shell recognize php command ?


also tried this :
pclose(popen('php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &'));
it returned:
./php.sh: line 11: syntax error near unexpected token `popen'
./php.sh: line 11: `pclose(popen('php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &'));'
I have no idea about this one.


looking forward to your reply.
thanks
Tanya
Jul 13 '07 #3

P: 13
You could use AJAX to execute a php page through HTTP Request Object. I don't have any reference code right now, but if you look into that it should be what you need.
Jul 13 '07 #4

pbmods
Expert 5K+
P: 5,821
Heya, Tanya.

I tried :
`php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &` ;
it returned :
php: command not found
I am wondering do I need to set up any config files in order to make shell recognize php command ?
You may need to use the absolute path to the php tool. Try /usr/bin/php, /bin/php or /usr/local/bin/php. If none of these work, then there is a good chance that the PHP command-line tool is not installed on your server.

If you want to run this command from a shell script, you don't need to use the backticks.

also tried this :
pclose(popen('php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &'));
it returned:
./php.sh: line 11: syntax error near unexpected token `popen'
./php.sh: line 11: `pclose(popen('php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &'));'
I have no idea about this one.
This code is designed to be run from a PHP file. popen() and pclose() are PHP functions. However, you may still get the 'php not found' error as above.
Jul 13 '07 #5

P: 43
heya, pbmods.

yes, I want to run this command from a shell script.

I tried :
pclose(popen(php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &));
and it returned:
./test.sh: line 9: syntax error near unexpected token `popen'
./test.sh: line 9: `pclose(popen(php /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &));'

and also the first method, none of that three exists.
well, how can I install the PHP command-line tool on my server ?
I am using apache2

thanks ,
Tanya

Heya, Tanya.



You may need to use the absolute path to the php tool. Try /usr/bin/php, /bin/php or /usr/local/bin/php. If none of these work, then there is a good chance that the PHP command-line tool is not installed on your server.

If you want to run this command from a shell script, you don't need to use the backticks.



This code is designed to be run from a PHP file. popen() and pclose() are PHP functions. However, you may still get the 'php not found' error as above.
Jul 25 '07 #6

P: 43
Heya, Pbmods,

it worked,

I checked the php was installed in the dir : /usr/bin/ and what I am using is php5 instead of php, so I used the code ( bash ) :

`/usr/bin/php5 /home/lmcelwain/public_html/R_LSM_Station/Create_Station/test.php &`

and it worked !

thanks a million !!! Pbmods
Tanya

Heya, Tanya.



You may need to use the absolute path to the php tool. Try /usr/bin/php, /bin/php or /usr/local/bin/php. If none of these work, then there is a good chance that the PHP command-line tool is not installed on your server.

If you want to run this command from a shell script, you don't need to use the backticks.



This code is designed to be run from a PHP file. popen() and pclose() are PHP functions. However, you may still get the 'php not found' error as above.
Jul 26 '07 #7

pbmods
Expert 5K+
P: 5,821
Heya, Tanya.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Jul 26 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.