如何使用CRON运行单个PHP实例? [英] How do you run a single PHP instance with CRON?

查看:100
本文介绍了如何使用CRON运行单个PHP实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用CRON运行PHP脚本的单个实例。也许有人可以帮助解释需要什么。当前,我有一个 startup 脚本,该脚本由 crontab 调用,该脚本检查以确保PHP脚本的实例是

I'm having trouble running a single instance of a PHP script using CRON. Perhaps someone can help explain what is needed. Currenty, I have a startup script that is called by crontab which checks to make sure an instance of a PHP script isn't already running before calling the PHP instance.

crontab -e 条目:

* * * * * /var/www/private/script.php >> /var/www/private/script.log 2>&1 &

./ startup

./startup

#!/bin/bash

if ps -ef | grep '[s]cript';
        then
                exit;
        else
                /usr/bin/php /var/www/private/script.php  >>/var/www/private/script.log 2>&1 &
                echo 'started'
fi

这似乎不起作用并且似乎无法记录任何错误以知道如何进行调试。

This doesn't seem to be working and I can't seem to get any errors logged to know how to proceed to debug this.

推荐答案

您可以将lockrun用于: http://www.unixwiz.net/tools/lockrun.html

You can use lockrun for that: http://www.unixwiz.net/tools/lockrun.html

* * * * * /usr/local/bin/lockrun --lockfile=/var/run/script.lockrun -- php /home/script.php

或使用Perl:

system('php /home/script.php') if ( ! `ps -aef|grep -v grep|grep script.php`);

这篇关于如何使用CRON运行单个PHP实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆