【问题标题】:Adding multiple PHP jobs into 1 crob job将多个 PHP 作业添加到 1 个 cron 作业中
【发布时间】:2012-02-08 05:07:10
【问题描述】:

我的主机帐户有 5 个 cron 作业限制,该帐户具有多个站点。所以我需要将所有的作业分成 5 组 cron 作业。被调用的文件都与wordpress插件、feedwordpress相关,格式

/usr/bin/curl --silent http://unique_website.com?update_feedwordpress=1

所以我计划有 5 个 cron 作业,每个作业调用 5 个这样的站点进行更新。关于如何实现这一点的任何想法?

【问题讨论】:

    标签: php wordpress cron


    【解决方案1】:

    你可以只写一个脚本来执行你所有的 curl 请求。

    #!/bin/sh
    /usr/bin/curl --silent http://unique_website.com?update_feedwordpress=1
    /usr/bin/curl --silent http://unique_website.com?update_feedwordpress=2
    /usr/bin/curl --silent http://unique_website.com?update_feedwordpress=3
    

    并更改您的 cron 任务以改为执行该脚本。

    【讨论】:

    • 我以前没有使用过 sh,我会在文件中放入什么?(对不起,我知道这是一个蹩脚的问题。我从主机上的 cron 中添加我会指向:/usr/ bin/curl --silent unique_website.com/cron.sh
    • 此代码应该是您必须放入文件中的所有代码。 cron 作业应该是 /bin/sh /path/to/script.sh 或可能是 /bin/bash /path/to/script.sh。如果您可以使脚本可执行,您可能可以通过简单的/path/to/script.sh
    【解决方案2】:

    你也可以这样做

    /usr/bin/curl --silent --config /path/to/your/config
    

    让你的配置文件看起来像

    #Update wordpress #1
    url = 'http://unique_website.com?update_feedwordpress=1'
    
    #Update wordpress #2
    url = 'http://unique_website.com?update_feedwordpress=2'
    
    #more ...
    

    对于 cronjob,它的优点是“一劳永逸”,如果您需要更改,只需更改配置文件。当然你也可以用 PHP 编写你的配置文件

    【讨论】:

      【解决方案3】:

      顺便说一句,使用 curl 你可以做以下任何事情:

      /usr/bin/curl --silent http://unique_website.com?update_feedwordpress=[1-5]
      /usr/bin/curl --silent http://unique_website.com?update_feedwordpress={1,2,3,5}
      /usr/bin/curl --silent http://{unique,other,third}_website.com?update_feedwordpress=1
      

      它会用不同的参数多次调用curl

      【讨论】:

        猜你喜欢
        • 2012-06-02
        • 2016-10-06
        • 2014-03-06
        • 2012-10-24
        • 2012-08-20
        • 1970-01-01
        • 1970-01-01
        • 2022-01-01
        • 1970-01-01
        相关资源
        最近更新 更多