我试图在mac中运行一个使用cron的php脚本。我希望这个php脚本每10秒运行一次。我在网上阅读了几个来源,据我的理解,如果我使用launchd,情况会更好。在任何情况下,我试图使它与cron一起工作,然后如果它工作良好,我可能尝试使用launchd。
这就是我所做的,但它每隔一分钟就跑一次:
*/1 * * * * /usr/bin/curl --silent --compressed http://localhost:8888/atms_final/data/demos/editing/loop_tasks.php 我如何将它改为每10秒运行一次
发布于 2016-10-14 16:41:45
对于10秒的重复率来说,cron有点粗粒度.
考虑做一个这样的小脚本,并将它保存为curler
#!/bin/bash
while :; do
echo curling...
/usr/bin/curl --silent --compressed http://localhost:8888/atms_final/data/demos/editing/loop_tasks.php
sleep 10
done然后,在终端中,您可以使其可执行(只需执行一次):
chmod +x curler然后,您可以在终端机上运行该程序:
./curler或者,您可以运行curler ,一次从cron运行。
发布于 2020-10-21 06:26:51
你可以这样做-
*/1 * * * * curl --silent --compressed http://localhost:8888
*/1 * * * * sleep 10; curl --silent --compressed http://localhost:8888
*/1 * * * * sleep 20; curl --silent --compressed http://localhost:8888
*/1 * * * * sleep 30; curl --silent --compressed http://localhost:8888
*/1 * * * * sleep 40; curl --silent --compressed http://localhost:8888
*/1 * * * * sleep 50; curl --silent --compressed http://localhost:8888解释-
因此,从技术上讲,您有6个cron作业--所有的任务都在每分钟运行,但是每个作业都有一个滞后的睡眠时间,这使得运行时间相差10秒。
https://stackoverflow.com/questions/40047229
复制相似问题