Kevin Florenz Daus
Kevin Florenz Daus

Reputation: 598

php execute system call and dont wait to finish

how do I execute system call in PHP without waiting for it to finish.

I need to run a script in my server every n seconds. I tried using cron but CRON cant run script every second its minimum is in minutes.

can someone help me out

Upvotes: 1

Views: 480

Answers (1)

baao
baao

Reputation: 73211

If it is a php file, you can do this with

 exec (nohup php /path/file.php);

nohup will put the proccess in the background, it will run even if you close a terminal or whatever.

To let it run every five seconds a simple

for ($i = 0; $i < 1;)
{
   exec (nohup php /path/file.php);
   sleep(5);
}

should be enough.

Works with shell scripts and other files, too - just add nohup before your command.

Remember that nohup will create a logfile for every run, to suppress the output use nohup like this:

nohup command >/dev/null 2>&1 

Upvotes: 2

Related Questions