Wyatt Jackson
Wyatt Jackson

Reputation: 303

Why am I getting file not found when using this popen command?

I'm attempting to use this code from here: https://stackoverflow.com/a/4350418/3672303

for ($i=0; $i<10; $i++) {
    // open ten processes
    for ($j=0; $j<10; $j++) {
        $pipe[$j] = popen('script2.php', 'w');
    }

    // wait for them to finish
    for ($j=0; $j<10; ++$j) {
        pclose($pipe[$j]);
    }
}

When I execute it, I get the following:

sh: 1: script2.php: not found
sh: 1: script2.php: not found
sh: 1: script2.php: not found...... (repeated a bunch of times)

script2.php is in the same directory. I tried using the full path to the file, and my result is the same.

I'm assuming it could be some type of weird PHP path/environment issue?... How do I fix?

Any help is much appreciated.

Upvotes: 0

Views: 299

Answers (1)

Wyatt Jackson
Wyatt Jackson

Reputation: 303

"Chris Hass" in the comments above came up with the solution. Changing this line worked.

$pipe[$j] = popen('script2.php', 'w');   // Does not work

to

popen('php ' . __DIR__ . '/script2.php', 'w')  // Works correctly.

Upvotes: 1

Related Questions