Notice (8): file_put_contents(): Write of 268 bytes failed with errno=28 No space left on device [CORE/src/Log/Engine/FileLog.php, line 140]

Notice: file_put_contents() [function.file-put-contents]: Write of 1108 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): unserialize() [<a href='https://secure.php.net/function.unserialize'>function.unserialize</a>]: Error at offset 4079 of 4085 bytes [APP/Controller/NewsController.php, line 5571]

Notice: file_put_contents() [function.file-put-contents]: Write of 2758 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Undefined array key "nsort" [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2074 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2098 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Undefined array key "nsort" [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2074 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2098 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): unserialize() [<a href='https://secure.php.net/function.unserialize'>function.unserialize</a>]: Error at offset 8178 of 8181 bytes [APP/Controller/NewsController.php, line 5571]

Notice: file_put_contents() [function.file-put-contents]: Write of 2395 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): unserialize() [<a href='https://secure.php.net/function.unserialize'>function.unserialize</a>]: Error at offset 4067 of 4085 bytes [APP/Controller/NewsController.php, line 5571]

Notice: file_put_contents() [function.file-put-contents]: Write of 2488 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
PHP程序级守护进程的实现与优化的使用方法 - 站长搜索
首页 > 资讯列表 > 编程/数据库 >>

PHP程序级守护进程的实现与优化的使用方法

Warning (2): Undefined array key "nsort" [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]
Notice: file_put_contents() [function.file-put-contents]: Write of 2422 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]

Notice: file_put_contents() [function.file-put-contents]: Write of 2446 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
">
Warning (2): Undefined array key "nsort" [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]

Notice: file_put_contents() [function.file-put-contents]: Write of 2422 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]

Notice: file_put_contents() [function.file-put-contents]: Write of 2446 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
2014-11-27 17:04:39 转载来源: 网络整理/侵权必删

本文为大家讲解的是PHP程序级守护进程的实现与优化的使用方法,感兴趣的同学参考下。 首先需要解释的是什么是守护进程

本文为大家讲解的是PHP程序守护进程实现优化使用方法,感兴趣的同学参考下。

首先需要解释的是什么是守护进程。

守护进程就是在后台一直运行的进程。比如我们启动的httpd,mysqld等进程都是常驻内存内运行的程序。

针对需求进行分析:

需求:有一个常驻队列messageQueue(假设在redis内存中),这个队列会有可能有请求不定期的往队列中增加元素。同时我们要求在队列中有元素的时候,按照队列顺序将元素pop出来,并进行处理(假设这个处理只是echo ‘test');

解决方法:

现在假设已经有了两个函数

function oPopMessageQueue(){ …} //获取队列最后一个元素;

function vDealElement($element) { …} 处理元素;

要求写出一个守护程序,完成上面的需求。

程序:

好了,这个程序很容易想到,可以使用while循环来做


while(true)
{
    if( $element  = oPopMessageQueue())
    {
        vDealElement($element);
    } 
}


考虑1 : 这个程序如果一直跑的话已经可以满足上面的需求了.

但是考虑到:1 用php进程跑有可能会由于各种情况(比如运行时间过长),进程挂了,这样程序就无法自动重连了.

方法:使用cron

我们在定时脚本中每10分钟起一个进程跑这个程序。

然后设置这个程序的运行时间为10分钟,10分钟后自动取消,于是代码变成


while(true)
{
    if($element = oPopMessageQueue())
    {
        vCheckTimeLimit();
        vDealElement($elemnt);
    }
}

$timeStart = 0;
function vCheckTimeLimit()
{
    global $timeStart;
    if(empty($timeStart))
    {
        $timeStart = time();
    } 

    if(time() - $timeStart > 60*10)
    {
        exit;
    }
}


考虑2,可能会有这种需求: 需要有随时让脚本暂停的功能:

于是考虑使用文件来增加暂停功能


while(true)
{
    if($element = oPopMessageQueue())
    {
        vCheckTimeLimit();
        vCheckEnd();
        vDealElement($elemnt);
    }
}

 
function vCheckEnd()
{
    if(file_exists("/home/JesephYe/end"))
    {
        exit;
    }
}


考虑3, 是否可以改成多线程的程序,让运行的效率更高?

这个只要把cron的10分钟起一个进程的限制改成每1分钟起一个进程就好了

这样能保证有10个线程在运行程序

但是有一个基本要求是:oPopMessageQueue()是一个原子操作


标签: PHP 程序 守护 进程 实现 优化 使用方法


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2025 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持