Reputation: 123
I am sending email in background process. For background process I am using symfony 2.0. Background works successfully. but in background I can't get session value.. Below code of index.php
session_start();
$_SESSION['album_upload'] = {"a","b"};
$command = file_get_contents('background.php');
$process = new PhpProcess($command);
$process->run();
below code of background.php
session_start();
$message = $_SESSION['album_upload'][0];
mail("[email protected]","example",$message,"From: $from\n"); // Session doesn't give any value.
If I remove session and just try to send mail like mail("[email protected]","example","example","From: $from\n");
then mail will send.
How to get the session value in background.php.
Upvotes: 0
Views: 565
Reputation: 983
Try to retrieve the session id from you're first script and pass it to the next one. You can do it with the session_id() func
Code Index.php
$session_id = session_id();
new PhpProcess($command, null, array('session_id' => $session_id));
$process->start();
while ($process->isRunning()) {// waiting for process to finish }
Code background.php
session_id($_SERVER['session_id']);
session_start();
$message = $_SESSION['album_upload'][0];
mail("[email protected]","example",$message,"From: $from\n"); // Session doesn't give any value.
Upvotes: 2
Reputation: 2076
PhpProcess runs as a seperate php process; this means it does not have access to the $_SESSION information that was available to the original request to your server.
You can pass the data as follows:
new PhpProcess($command, null, array('album_upload' => $_SESSION['album_upload'][0]));
That should allow you to acccess the data in your background script as the variable:
$_SERVER['album_upload']
Upvotes: 2