I need to receive a piece of data in real time for processing. It must be in seconds. How should I process it?
習慣沉默2017-05-16 13:03:44
If the system uses systemd, you can use systemd.timer
to set seconds or even millisecond-level scheduled tasks.
Specific reference: here
曾经蜡笔没有小新2017-05-16 13:03:44
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
我想大声告诉你2017-05-16 13:03:44
crontab can’t handle it in seconds, you can only use the resident process to solve it
天蓬老师2017-05-16 13:03:44
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);
}