Forum Moderators: coopster

Message Too Old, No Replies

php command line

"no input file specified"

         

jamie

10:31 am on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



apparently this is a bug with newer versions of php, it misses the env SCRIPT_FILENAME when used from command line

see php.net commandline features [es2.php.net]

my crontab looks like:
/opt/bin/php -q /var/www/htdocs/scripts/test.php

when i run the script from the /var/www/htdocs/scripts directory it runs fine:

% /opt/bin/php -q test.php

but when i use the full path to the script in the cron job, it exits with the error message "no input file specified".

apparently i need to add the SCRIPT_FILENAME var to the env variables - does anyone know how to do this? or should i simply install an older version of php as cgi?

many thanks

pete_m

10:35 am on Jun 7, 2004 (gmt 0)

10+ Year Member



Have you tried omitting the -q and just passing the filename, like:

/opt/bin/php /var/www/htdocs/scripts/test.php

jamie

11:04 am on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi pete,

no unfortunately doesn't work. have recompiled using --enable-discard-path (recommended somewhere) but still no joy.

the script works fine without the path, but with the full path it still returns same input file error :-(

will keep looking

pete_m

11:20 am on Jun 7, 2004 (gmt 0)

10+ Year Member



Another option is to make the php file executable in itself. All you need to do is add the following line to the top of the file:
#!/opt/bin/php

so that the file looks like

#!/opt/bin/php
<?php
..blah

and set execute permissions on that file for the relevant user (i.e. whichever user owns the crontab).

jamie

12:00 pm on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi pete,

thanks for input, but that idea desn't work either. this is getting weirder and weirder.

sometimes using the full path works and then 1 minute later for no apparent reason it does not work. i am not changing anything between tries.

it still will not work consistently when i use the full path.

hmmmm

pete_m

12:08 pm on Jun 7, 2004 (gmt 0)

10+ Year Member



Just to clarify:

If you make the php script executable, then you don't need to invoke the php parser directly.

In other words, your line in the crontab can just read:

/var/www/htdocs/scripts/test.php

If the script has execute permissions set, then the server will see the first line (#!/opt/bin/php) and use this program to execute the remainder of the script.

You should test that the test.php script is executable by just running it from the command line:

% /var/www/htdocs/scripts/test.php

Apologies if you already know this!

jamie

12:49 pm on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi pete,

thanks for your step by step guide.

i have done as you say and when i run ./test.php it returns "bad interpreter: no such file or directory"

the shebang line is identical to another php script (with a simple mail() function) which works fine ./testmail.php

the script works perfectly if called in the browser.

i think we are getting somewhere ;)

pete_m

4:45 pm on Jun 7, 2004 (gmt 0)

10+ Year Member



Hi Jamie

Off the top of my head there are a couple of reasons why the test.php script isn't working.

1 - The shebang line should have *no spaces* in it, and should point to the php interpreter

2 - You may have created the script on a Windows machine, and the text file has Windows line breaks ("\r\n"). Unix line breaks have a different format ("\n").
Open the the test.php file in a unix text editor, and replace those linebreaks. Alternatively, use a Windows text editor like Textpad and save test.php as Unix format.

jamie

7:03 pm on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



pete, thanks so much for your patience :-)

i finally got it working. i opened it up in vi and redid the shebang line and am now simply calling it using the /fullpath/to/script.php in the cron job. working a treat.

(at last ;)

cheers

pete_m

6:55 am on Jun 8, 2004 (gmt 0)

10+ Year Member



No problems, glad you got it working.