0

I am trying to use a proc_open() in my php script to call and execute another php script. The following is the code:

$descriptors = array(
 0 => array("pipe","r"),
 1 => array("pipe","w"),
 2 => array("file","./error_log.txt","a")
) ;
$cwd="./";
$process=proc_open('php reversegame.php &', $descriptors,$pipes,$cwd); 
if (is_resource($process)) {
  $return_value = proc_close($process);
}

This writes the following error in the error_log.txt

PHP: syntax error, unexpected '&' in /etc/php5/cli/php.ini on line 107

I am new to proc_open, and still trying to get a grasp on the usage of this function. I am actually trying to execute this php script simultaneously while running another script!

2

4 Answers 4

1

remove & from this line

$process=proc_open('php reversegame.php ', $descriptors,$pipes,$cwd); 
Sign up to request clarification or add additional context in comments.

1 Comment

But I want the script to execute in the background.
0

I am also faced this error. But this error should not block your script to work. This error comes due to using & operator in INI file (like using error_reporting E_ALL & ~E_NOTICE).

2 Comments

No, I did not solve the issue as It not block the php scripts. Some settings like error_reporting work in php code too, So its better to remove from ini file and then put in code by using ini_set("error_reporting", E_ALL & ~E_NOTICE) OR direct function error_reporting(E_ALL & ~E_NOTICE).
Anyways, heres the solution to that. stackoverflow.com/questions/32901337/…
0

You might have disabled proc_open.

search for disable_functions you will see disable_functions = show_source,system,shell_exec,passthru,exec,phpinfo,proc_open.

Now change it to disable_functions = .

And restart all service and try.

Comments

0

You will need to look into forking the process using pcntl_fork()

I don't know if this will let you put the other script in the background but you should be able to fork the current thread and then end the current thread with the new forked thread still running.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.