python - I have a second-level task. How to handle the crond service in Linux? It takes at least 1 minute. PHP
習慣沉默
習慣沉默 2017-05-16 13:01:44
0
4
659

I need to receive a piece of data in real time for processing. It must be in seconds. How should I process it?

習慣沉默
習慣沉默

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