Page 1 of 1

Execute PHP file from command line, kinda

Posted: Mon Aug 11, 2008 9:44 am
by shiznatix
I have several cron jobs that I use to get data from external XML files and the likes to keep out site updated. Sometimes these fail if the outside sources server is not on the up and up or whatever. So I setup a section that would allow an admin to rerun the script. Basically the cron job is just to run a job like this:

Code: Select all

php /path/to/file/file.php
which works great. Now I am trying to get this to happen from a call from something like exec(), passthru(), system(), or something. Right now, nothing works! I have this:

Code: Select all

$command = escapeshellcmd('php /path/to/files/file.php 2008 08 5 0');
system($command, $output);
$command is a perfectly valid command, works perfectly from the command line, but I get this response from a system() call:
Status: 404
X-Powered-By: PHP/5.2.3
Content-type: text/html

No input file specified.
So I'm like, blah. I thought, "maybe permissions" but alas, nope. So, can someone help me out here?

Re: Execute PHP file from command line, kinda

Posted: Mon Aug 11, 2008 10:16 am
by idevlin
In the first example you have "/path/to/file/file.php" and in the second one you have "/path/to/files/file.php"

So "file" and "files", the second one is wrong?

Re: Execute PHP file from command line, kinda

Posted: Tue Aug 12, 2008 1:57 am
by shiznatix
idevlin wrote:In the first example you have "/path/to/file/file.php" and in the second one you have "/path/to/files/file.php"

So "file" and "files", the second one is wrong?
good eye but both paths are made up. I just was hiding my super-top-secret-awesome-9000-zaquier file structure.

Re: Execute PHP file from command line, kinda

Posted: Tue Aug 12, 2008 6:01 am
by EverLearning
I think that with you need to use -f switch if you're invoking your script like that

Code: Select all

$command = escapeshellcmd('php -f /path/to/files/file.php 2008 08 5 0');
Also if your cron file has a shebang line at the begining of the file, try just calling it directly

Code: Select all

$command = escapeshellcmd('/path/to/files/file.php 2008 08 5 0');

Re: Execute PHP file from command line, kinda

Posted: Tue Aug 12, 2008 8:25 am
by shiznatix
Alas, still having the same problem. Not sure why it always says "no input file specified", that is what I think the root of my problem is.

Re: Execute PHP file from command line, kinda

Posted: Tue Aug 12, 2008 8:33 am
by EverLearning
Try putting the full path to php executable /usr/bin/php or /usr/local/bin/php. Also are your really sure that the path to your php file is right? It may be right when run from cron, but since you're trying to run it from a web page, maybe something has changed?
Try listing the files from that directory with

Code: Select all

system('ls -al', $output)
or something similar.

Re: Execute PHP file from command line, kinda

Posted: Tue Aug 12, 2008 9:00 am
by shiznatix
arg the problem was I had to use php5 for whatever reason. I always used php but when I added php5 everything worked. arg.

Re: Execute PHP file from command line, kinda

Posted: Tue Aug 12, 2008 10:39 am
by idevlin
How odd, are there two different versions of php installed then? php invokes version 4 and php5 invokes version 5?

The parameters must be different between versions then.