How to create a http response for a request associated with a different PHP session?
Is it possible to create a http response for requests associated with a different PHP session? If so, how to do that?
I'm c开发者_C百科reating a script language to make it easier for PHP developers to handle phone interactions. My application receives phone calls and then activates the user scripts associated with those calls.
Scripts are processed in real time. Since I don't know the number of commands in the scripts, I have to create and send individual REST responses for each command until somebody issues a hangup.
Is there any way to do that without having to stop the current function, send the response, and then resume the script the next time the phone server sends me a request?
Ideally, I would love to remain in the current PHP function sending responses for each http request without having to stop at each time... would curl -- or anything else -- help me with that?
Thanks in advance,
Leo
I hope i got right what you're trying to do,
well, if you have the desired other session's id, just use session_id() function to set which session actually used is used, for example:
#Assuming url like www.example.com/?session_id=123456;
$current_session_id = session_id();
$desired_session_id = $_GET['session_id'];
session_id($desired_session_id); #that's where we switch to the desired session
var_dump($_SESSION); #will dump session with id 123456
session_id($current_session_id); #switching back to the previous session id
This should work, I believe that I used something like this in the past, but double check me on that.
You can use multi-curl to send multiple requests, but it seems like you need to send the commands in order. Another option would be to use forking, which creates a copy of the current process. You can check if you are the "parent" or "child" process. The "parent" process then monitors the "child" processes. I've done this with up 50 child processes running at once off of 1 parent process. http://php.net/manual/en/function.pcntl-fork.php
If you just want to send the command, and don't care about the output, just use the exec function. In the example below, PHP won't wait for a response or for the script to complete.
exec("send_command.php > /dev/null &");
精彩评论