简体   繁体   中英

Run a php script every 5 seconds by using a shell script

I would like to run a php script every 5 seconds.

That's what I've done :

(essay.sh file)

#!/bin/bash

while :
do
    php a_file.php
    sleep 5
done

(the php file in a nutshell)

<?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).

When I use the direct url of a_file.php in my browser the script is working, and a new json.txt is generated.

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.

Try to set the permissions to 775 or run the script as the owner of that json file.

I have tried your script in my pc and found out it works fine. This is the file privilege i set: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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