I need to receive a piece of data in real time for processing. It must be in seconds. How should I process it?
If the system uses systemd, you can use systemd.timer to set seconds or even millisecond-level scheduled tasks. Specific reference: here
systemd.timer
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
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);}
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:
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.
crontab can’t handle it in seconds, you can only use the resident process to solve it
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);
}