php上的睡眠功能 [英] Sleep function on php

查看:102
本文介绍了php上的睡眠功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为使用 cron 作业的可能替代方案,我发现了 sleep 功能.我以前从未使用过这个.

As a possible alternative to using cron jobs, I found the sleep function. I have never used this before.

如果我告诉我的脚本在某种循环内运行,并且在该循环内我有这样的指令

If I tell my script to run inside a kind of loop, and inside that loop I have an instruction like this

# sleeps for 86400 seconds or one day
sleep(86400);

我的脚本会在 1 天后再次启动吗?即使在那段时间内不再在我的网络浏览器上访问它?我认为这是不可能的,但我是来请教专家的.

will my script be launched again after 1 day? even if don't access it on my web browser again within that period? I think is not possible, but I'm here to ask an expert about it.

推荐答案

根据我的经验,以这种方式使用 PHP 的主要问题不是 Web 服务器超时(有一些方法可以解决这个问题,但在服务器和平台)但内存泄漏.

The main problem with using PHP this way is, in my experience, not web server timeouts (there are ways to handle that with difficulty varying on the server and the platform) but memory leaks.

简单的 PHP 代码往往会泄漏大量的内存;在我进行了一些分析并放置了一些 unset 之后,我编写的大多数脚本都能够完成数百倍的工作.而且我永远无法以这种方式防止所有泄漏.我还被告知标准库中存在内存泄漏,如果为真,则无法编写在循环中长时间运行的守护进程.

Straightforward PHP code tends to leak a lot of memory; most of the scripts I wrote were able to do hundreds of times as many work after I did some analysis and placed some unsets. And I was never able to prevent all the leaks this way. I'm also told there are memory leaks in the standard library, which, if true, makes it impossible to write daemons that would run for a long time in loops.

这篇关于php上的睡眠功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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