dongyuduan1890 2016-03-17 17:00
浏览 43


I have a wordpress php script running as a cron job. it's currently running once a minute per domain indefinitely.

    /usr/bin/php -q /home/domain1/public_html/wp-content/plugins/tdw/postit.php > /dev/null 2>&1

The problem is my server is getting big with 50+ domains and the crons are running into each other causing errors or crashing the database.

is there a way that i can make it run sequentially? like run domain1 script wait one minute then run domain2...looping through the url list.

thank you for your help.

  • 写回答

1条回答 默认 最新

  • duanliusong6395 2016-03-17 17:09

    Put them in a bash script, like

    /usr/bin/php -q /home/domain1/public_html/wp-content/plugins/tdw/postit.php > /dev/null
    sleep 60s
    /usr/bin/php -q /home/domain2/public_html/wp-content/plugins/tdw/postit.php > /dev/null
    sleep 60s
    /usr/bin/php -q /home/domain3/public_html/wp-content/plugins/tdw/postit.php > /dev/null
    sleep 60s
    # and so on...

    and start that from cron.

    If the pathes are all alike except the domain name, you could also use a php script, which generates the correct path for every domain and then executes the script via exec(). For example, it could iterate over the contents of the /home folder via the directory functions of PHP. That way, you do not have to update your script when you add a domain.

    A script like that would look like

    $template = '/usr/bin/php -q /home/%s/public_html/wp-content/plugins/tdw/postit.php > /dev/null';
    if ($handle = opendir('/home')) {
        while (false !== ($entry = readdir($handle))) {
            $command = sprintf($template, entry);
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥15 三维直角坐标系下,给定一个平面内四个点坐标,如何将四个点逆时针排序
    • ¥15 UnityWebRequest访问内网地址502
    • ¥20 Python语言来实现牛顿法(Newton's Method)解决非线性(系统)方程的问题。
    • ¥15 matlab控制工业相机采集图像
    • ¥25 R里做折线图和柱状图
    • ¥20 使用kokkos移植项目,遇到问题
    • ¥15 求该问题的Matlab代码
    • ¥15 python下使用pdpbox为何提示has no attribute 'pdp_isolate'?
    • ¥15 求java web病房管理系统项目,用netbeans做的
    • ¥15 python图片画不出来