0

I noticed exec and shell_exec is causing perpetual loading.

Basically, I'm trying to do something as simple as loading a PHP script in the background. When I try to do that, it just loads and loads.

My code is as follows

exec('php test.php -- '.escapeshellarg($param1).'  > /dev/null  ');

I first thought it was my other script, so I pointed it to a file with just:

echo $agrv[1];

But it still loads perpetually.

David Harris
  • 2,697
  • 15
  • 27
user1687621
  • 425
  • 1
  • 6
  • 14
  • 2
    Loads and loads what? Your "question" isn't clear – zerkms Dec 30 '12 at 02:13
  • 1
    Exactly what is this `test.php` script doing? Exec() will not return until the process you've spawned (php running test.php) exits. If test.php is (say) requesting input, it'll just sit there forever because you never provide that input. – Marc B Dec 30 '12 at 02:25
  • Why are you even calling `exec('php test.php ...')`? Why not `include(test.php)`? And why is it taking forever to execute? What is `test.php` doing? – cegfault Dec 30 '12 at 02:46
  • You keep saying that word, "perpetual", I don't think it means what you think it means. – Petah Dec 30 '12 at 02:53

1 Answers1

0

Don't wait for the process to exit

exec() waits for the process to give an exit code. The link I provided above may help you.

Oh, and since you tagged Linux for whatever reason, I assume you're on a Linux distro.

You could consider this, aswell: http://ca1.php.net/pcntl_fork

Community
  • 1
  • 1
David Harris
  • 2,697
  • 15
  • 27