python - 我有个秒级任务 怎么处理 linux 的crond服务 最少是1分钟 php
習慣沉默
習慣沉默 2017-05-16 13:01:44
0
4
583

我需要实时接收一个数据去处理,必须是秒级,怎么处理呢

習慣沉默
習慣沉默

reply all(4)
習慣沉默

If the system uses systemd, you can use systemd.timer to set seconds or even millisecond-level scheduled tasks.
Specific reference: here

曾经蜡笔没有小新

The default minimum unit of crontab is minutes, but it can also be implemented in some tricky ways. For example, execute every 10 seconds:

* * * * * php /home/test.php
* * * * * sleep 10; php /home/test.php
* * * * * sleep 20; php /home/test.php
* * * * * sleep 30; php /home/test.php
* * * * * sleep 40; php /home/test.php
* * * * * sleep 50; php /home/test.php

Per second, it can also be achieved in the above way, but it is a lot and is not recommended, so using a shell script is a better choice.

#!/bin/bash  
  
step=1 #间隔的秒数,不能大于60  
  
for (( i = 0; i < 60; i=(i+step) )); do  
    $(php '/home/test.php')  
    sleep $step  
done  
  
exit 0  
我想大声告诉你

crontab can’t handle it in seconds, you can only use the resident process to solve it

Peter_Zhu

The minimum execution time granularity of crontab is one minute. For seconds, you can start an infinite loop to continuously obtain data.
while(true){
file_get_contents('get_data_controller');
sleep(1);
}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!