从php文件中运行cron作业

I have a problem where my hosting company won't let me run a cron job in this format from my control panel:

/usr/bin/php /home/sites/MYDOMAIN.com/index.php?option=com_community&task=cron

Or:

www.MYDOMAINNAME.com/index.php?option=com_community&task=cron

Now if i run the second job in a browser i.e.:

www.MYDOMAINNAME.com/index.php?option=com_community&task=cron

this works fine in a browser

My support says I have to create a file to run the URL. The only problem is I don’t know how to run a URL in PHP. I have asked a few sites. But nothing. My file is called bump.php and has the following code:

lynx -dump http://www.MYDOMAIN.com/index.php?option=com_community&task=cron

this is what i have in the file

<?php


echo file_get_contents('DOMAIN.com/index.php?option=com_community&task=cron');

?>

You have to access the file in question via your webserver, not directly by file access. If you access it by file-access, it will just return the php code and not execute it.

There are several options on how to access files via webserver. One is your shown method with file_get_contents. You will need to add http:// in front of the url to tell PHP that you want it accessed remotly and not as a local file.

file_get_contents is not allways configured to allow remotely downloading files. In these cases, it will not work. You can check this link to see the configuration setting for remote accessing files: http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

Another solution is to use the curl extension (if available)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);

curl_close($ch);

http://www.php.net/manual/en/function.curl-exec.php

There are other extensions if curl is also not available...