I’ve been running a simple php script (which logs its running time in a text log file). From browser it runs fine, but as I use the scheduled tasks in my plesk 10.3.1 panel as follow:
*/5 * * * * php /var/www/vhosts/eblogs.co.uk/httpdocs/frostbox/cron/crone_test.php
It does run right after five minutes but does not write anything in the text file and sends me following notification messages via email:
php [-f from_encoding] [-t to_encoding] [-s string] [files...]
php -l
php -r encoding_alias
-l,--list
lists all available encodings
-r,--resolve encoding_alias
resolve encoding to its (Encode) canonical name
-f,--from from_encoding
when omitted, the current locale will be used
-t,--to to_encoding
when omitted, the current locale will be used
-s,--string string
"string" will be the input instead of STDIN or files
The following are mainly of interest to Encode hackers:
-D,--debug show debug information
-C N | -c | -p check the validity of the input
-S,--scheme scheme use the scheme for conversion
What should I add in the following line?
php /var/www/vhosts/eblogs.co.uk/httpdocs/frostbox/cron/crone_test.php
3
Answers
Add the following at the top of the php script:
(assuming php exists at /usr/bin)
Hope that helps !
You can use “curl” … like this:
The text you get back is the usage message of piconv. This has absolutely nothing to do with PHP, the scripting language. What you probably want to do is one of the following:
Alternative 1: Using the PHP command line interpreter
You need to call the actual php interpreter on your system. This might be
/usr/bin/php5
, so your crontab line would look likeHowever not every setup has this command line interpreter installed. It might happen that only the apache module is installed.
Alternative 2: Using an HTTP(S) request
If you don’t have the right to install the command line tool, have a look if wget or curl is installed. If so, you can use them to invoke the script by sending a request to the web server.
Using wget:
-O /dev/null
tells it to save the web page generated by your script in/dev/null
. It is a special file that basically immediately forgets all data written to it. So this parameter avoids that any new file with the web page contents is created and lies around in your server’s file system.Using curl:
-o /dev/null
has the same function here as the version with the capital O above for wget.