Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

(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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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");
share|improve this answer
    
Thanks muchly! That did it. –  EmmyS Feb 24 '11 at 17:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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