Home  >  Article  >  Backend Development  >  服务器执行自动执行程序

服务器执行自动执行程序

WBOY
WBOYOriginal
2016-07-06 13:51:341172browse

有什么技术,可以让服务器每个一段时间调用一次程序

回复内容:

有什么技术,可以让服务器每个一段时间调用一次程序

得看你什么程序,什么服务器。
Linux服务器分钟级的定时任务就用crontab,秒级需要自己写脚本了。
Windows可以有计划任务或者写一些程序(Java,.NET)之类的来做调度
说白了就是调度

用crontab吧

PHP有个方法可以忽略用户关闭窗口能够跑一段不短的时间

<code><?php while(1) {
    //这里写你的业务逻辑代码.
    //注意!如果用到数据库,每次循环都要显式关闭MySQL连接.
    //同时要注意对可能的连接失败,操作失败进行处理.
    //另外记得用unset释放掉不再使用的变量,避免内存泄漏.
    $str = file_get_contents('http://php.net/images/logo.php');
    unset($str);
    sleep(2); //每隔2秒
}</code></code>

<code>*/2 * * * *  /path/to/your/php   /path/to/your/php/script >> /tmp/oxox.log</code>

crontab

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn