扫码关注官方订阅号
我这样请求是1分钟,怎么样实现1秒
闭关修行中......
用脚本for循环去执行。否则如果你要修改秒数间隔,或者修改执行内容,你还一行一行改么。
app.sh
step=1 for (( i=0;i<60;i=(i+$step) )); do curl http://www.google.com & sleep $step done
crontab -e
* * * * * sh /app.sh
* * * * * sleep 1s;curl http://www.baidu.com * * * * * sleep 2s;curl http://www.baidu.com ... * * * * * sleep 59s;curl http://www.baidu.com
大概就是这个意思,你可以写成一个脚本来执行。在脚本中使用循环,每次循环sleep 1s;然后执行curl,循环60次。然后每分钟执行一次这个脚本就可以实现每秒请求一次了。
目前了解到秒级的处理方案有两个。第一:写一个死循环脚本:
while(true){ do command }
第二:就是@白菜1031提的那个方法写60行crontab
crontab的精度是一分钟 所以想到直接crontab这条路已经死了。只能写个shell。 shell sleep的时间为一秒可以参考crontab实现How to get a unix script to run every 15 seconds?
简单的,可以用:
while sleep 1; do curl -i http://xxx...xxxx/test; done
接下来,你可能会考虑如何在后台运行,有几个选择:
nohup
init.d
systemctl
supervisor
这儿的解答可以帮助你。
不需要脚本
* * * * * for i in {0..59}; do curl wwww.baidu.com & sleep 1; done
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
用脚本for循环去执行。否则如果你要修改秒数间隔,或者修改执行内容,你还一行一行改么。
app.sh
crontab -e
大概就是这个意思,你可以写成一个脚本来执行。
在脚本中使用循环,每次循环sleep 1s;然后执行curl,循环60次。然后每分钟执行一次这个脚本就可以实现每秒请求一次了。
目前了解到秒级的处理方案有两个。
第一:写一个死循环脚本:
第二:就是@白菜1031提的那个方法写60行crontab
crontab的精度是一分钟 所以想到直接crontab这条路已经死了。
只能写个shell。 shell sleep的时间为一秒
可以参考
crontab实现
How to get a unix script to run every 15 seconds?
简单的,可以用:
接下来,你可能会考虑如何在后台运行,有几个选择:
nohup
init.d
systemctl
supervisor
这儿的解答可以帮助你。
不需要脚本