PHP - Script don't finish via shell_exec when passing session_id

42 Views Asked by At

Hy guys,

if I call a php script via shell_exec and pass the session_id via parameters, the called php script is not terminated if I call the session_id with "session_id(previous_session_id);" and "start_session();" in the second script. The second script stops at point "session_start();"

Script 1 (executer.php)

<?php
  session_start();
  $sessionID = session_id();
  $return = shell_exec('php '.__DIR__.'/job.php sessionID='.$sessionID);
  print_r($return);
?>

Script 2 (job.php)

<?php
  parse_str($argv[1], $params); //Get params
  
  session_id($params['sessionID']); //Set the previous session_id
  session_start(); //Start the previous session 

  $returnValues = array('Submitted Arguments'=>$argv);
  print_r($returnValues);
?>

Can you please help me?

i tried also with session_write_close();

1

There are 1 best solutions below

1
Georg On

I'm an idiot. I tried with session_write_close() on the wrong position. I put it before exec call (job_executer Script) and now, it works :)