readonly
readonly

Reputation: 355584

PHP fork without having child inherit the parent's file descriptors?

I'm trying to run a shell command using the backtick operators, but the fact that the child process inherits php's open file descriptors is problematic. Is there a way to keep this from happening?

I'm running PHP 5.1.2

Upvotes: 5

Views: 1348

Answers (2)

Eli
Eli

Reputation: 99398

The only way I really know of is to have the children open up their own resources after forking.

There is a fairly decent tutorial on pcntl here:

http://www.hackingwithphp.com/16/0/0/miscellaneous-topics http://www.hackingwithphp.com/16/1/4/duplication-of-resources-when-forking

Upvotes: 2

Greg
Greg

Reputation: 12837

This worked for me:

$cmd_to_run = escapeshellarg('/path/to/file --args');
`echo $cmd_to_run | /bin/at now`;

Replace the '/path/to/file --args' part with the command that you want to run. The 'at' command uses your cron daemon to schedule tasks.

Upvotes: 0

Related Questions