The smallest unit of execution time in the crontab minutes.
If you need to execute in seconds, there are two ways:
Method One: be achieved through sleep
Example:
1, create a test.php file, here are distinguished by good test printing time.
<?php file_put_contents('log.txt',date('Y-m-d H:i:s') . "\n", FILE_APPEND); ?>
2, to ensure that individual access test.php file to print the log.
3, edit the crontab file, the crontab -e command, for example, I want to run every 15 seconds, as follows:
* * * * * curl "http://127.0.0.1/testtask/test.php" && sleep 15;curl "http://127.0.0.1/testtask/test.php" && sleep 15;curl "http://127.0.0.1/testtask/test.php" && sleep 15;curl "http://127.0.0.1/testtask/test.php"
4, print the results, you can see the results in real time through the tail -f log.txt command.
It can be seen every 15 seconds to print out the results.
Method Two: be accomplished by adding an intermediate shell scripts
Example:
1, add a script file test.sh, reads as follows: I am here is to choose two seconds once.
step=2 #间隔秒数 for ((i = 0; i < 60; i = (i + step))); do $(curl "http://127.0.0.1/testtask/test.php") sleep $step done exit 0
2, edit the crontab file
* * * * * /phpstudy/www/testtask/test.sh
3, print results