简体   繁体   English

通过使用Shell脚本每5秒钟运行一次php脚本

[英]Run a php script every 5 seconds by using a shell script

I would like to run a php script every 5 seconds. 我想每5秒运行一个php脚本。

That's what I've done : 那就是我所做的:

(essay.sh file) (essay.sh文件)

#!/bin/bash

while :
do
    php a_file.php
    sleep 5
done

(the php file in a nutshell) (简而言之,php文件)

<?php
// sql call

// sql into $json

$file = 'json.txt';

file_put_contents($file, $json);
?>

There is no error when I do: ./essay.sh, but the json.txt is not refreshed (nothing happen, and I've set the rights to 0755 for the both files). 当我执行以下操作时没有错误:./essay.sh,但是json.txt没有刷新(什么也没有发生,并且我将两个文件的权限都设置为0755)。

When I use the direct url of a_file.php in my browser the script is working, and a new json.txt is generated. 当我在浏览器中使用a_file.php的直接URL时,脚本正在运行,并且会生成一个新的json.txt。

Thank you for your help ! 谢谢您的帮助 !

Because your are setting 0755 you need to run your script as the same user as the owner of the json file. 因为您正在设置0755,所以需要以与json文件所有者相同的用户身份运行脚本。

Try to set the permissions to 775 or run the script as the owner of that json file. 尝试将权限设置为775或以该json文件的所有者身份运行脚本。

I have tried your script in my pc and found out it works fine. 我已经在我的电脑中尝试了您的脚本,发现它可以正常工作。 This is the file privilege i set: 这是我设置的文件特权: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM