I am writing a c program that will call a php script every few seconds in the background. So when you first call this program, it will create a child process through fork, and then exit the parent process, while the child process will be in an infinite loop. So far inside that infinte loop, I have the line system("echo hello >> daemon.txt")
inside hte while loop, and it updates accordingly, so I know that the process is working. However when I call my script, it seems like it does not execute.
My php script timeChecker.php
#!/usr/bin/php <?php $handle =fopen("hello","a"); fwrite($handle, "boo "); fclose($handle); ?>
When called from commandline using either php timeChecker.php or ./timeChecker.php, the code executes as it should.
However, after trying multiple methods of calling the command such as system("php timeChecker.php")
, system("/usr/bin/php timeChecker.php")
, system("/usr/bin/php var/www/timeChecker.php")
, system("/var/www/timeChecker.php")
and all variations of that, the code still does not execute. Is there something simple that I am doing wrong? Or should I simply use a different method of checking the script?
As you are suggesting in your question, the php script is in "/var/www". Do you have the privileges to execute in that directory?
test is the c program calling the script through system(). I've made it work this way:
sudo mkdir /var/www/script_dir
sudo mv timeChecker.php /var/www/script_dir
sudo mv test /var/www/script_dir
sudo chown -R myusername:myusername /var/www/script_dir
Execute test from the script_dir.