2

(Possibly this belongs on stackoverflow, although it's not really a programming issue since the code works when run directly. If it needs to be moved, though, no problem.)

I have a PHP file (which consumers a National Weather Service web service via SOAP, if it matters) that I need to run on a scheduled basis. I'm trying to set up a cron job in Webmin. If I use an absolute path to the file in the Command field, when I run it I get some strange errors:

/var/www/html/mysite.com/test/ndfdXMLclient.php: line 1: ?php: No such file or directory
/var/www/html/mysite.com/test/ndfdXMLclient.php: line 2: //: is a directory
/var/www/html/mysite.com/test/ndfdXMLclient.php: line 3: //DOCUMENTATION: No such file or directory
/var/www/html/mysite.com/test/ndfdXMLclient.php: line 4: //: is a directory
/var/www/html/mysite.com/test/ndfdXMLclient.php: line 5: syntax error near unexpected token `"running client code",'
/var/www/html/mysite.com/test/ndfdXMLclient.php: line 5: `error_log("running client code", 1, "myemail@gmail.com");'

The actual code in my file for those 5 lines looks like this:

<?php
//  ***************************************************************************
//DOCUMENTATION FROM WEATHER.GOV ALL STORED IN xmlClientComments.txt
//  ***************************************************************************
error_log("running client code", 1, "myemail@gmail.com");

The code runs perfectly fine when I run it directly in my browser, so why doesn't webmin recognize it as code? (The same thing happens if I enter the actual URL in the command field - http://mysite.com/test/ndfdXMLclient.php.)

I've never worked with webmin before; most of our hosts' cron control panels allow cron jobs to run PHP files like this with no issue. Is there some trick to getting webmin to read php as actual php?

1 Answer 1

2

You probably need to add the hashbang at the top of your script so the server knows where to find PHP to precess the script.

Make sure the path to the PHP executable is correct for your server.

#!/usr/bin/php -q
<?php
//  ***************************************************************************
//DOCUMENTATION FROM WEATHER.GOV ALL STORED IN xmlClientComments.txt
//  ***************************************************************************
error_log("running client code", 1, "myemail@gmail.com");
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.