Web Hosting Talk







View Full Version : Launch PHP files from linux batch script


horizon
03-21-2010, 11:03 AM
Hi, I'm not quite familiar with linux batch scripts. I'm trying to launch a PHP file (with a cron job - every midnights) so that this PHP file would connect with cURL to another location and obtain responses.

Also, once this batch script created, it is possible to add this script file from cPanel ? If so, I'd like to know how it works. :)

Steve_Arm
03-21-2010, 01:04 PM
To run php from the command line you point to the php binary passing the -f argument with the path to the file you want to execute and then additional arguments for php (optional).

So in a machine it would be:

/usr/local/php/bin/php -f /path/to/php/file.php

horizon
03-21-2010, 01:20 PM
To run php from the command line you point to the php binary passing the -f argument with the path to the file you want to execute and then additional arguments for php (optional).

So in a machine it would be:

/usr/local/php/bin/php -f /path/to/php/file.php

Is there any way to track the bolded path automatically from command in the mean time if the path cannot be known or remembered ?

Neva Digital
03-21-2010, 01:42 PM
Horizon, using the command `which php` should tell you the correct path to it.

horizon
03-21-2010, 01:52 PM
Thanks. Although, by using this command, what happens if it doesn't return the correct path from where it should rather be located ? I presume the modifications would need to be done in, either, php.ini or httpd.conf ?

dreamlandbeach
03-24-2010, 12:47 AM
Thanks. Although, by using this command, what happens if it doesn't return the correct path from where it should rather be located ? I presume the modifications would need to be done in, either, php.ini or httpd.conf ?

you dont need to edit php.ini or httpd.conf to execute php from bash

nwmcsween
03-24-2010, 02:50 AM
/usr/bin/env php