drcomwc134525 2014-05-26 14:58
浏览 34
已采纳

从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');

?>
  • 写回答

1条回答 默认 最新

  • douji1853 2014-05-26 15:36
    关注

    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...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度