2

I need to call php script from main script that will run in background (i just want to call and proceed without waiting for response) But I need access to user session in called script

2
  • Why don't you have access to the user session in that script? Commented May 2, 2012 at 9:20
  • If I call script by system() call using wget i don't have access to specific session anymore. Commented May 2, 2012 at 9:27

4 Answers 4

2

My advice is don't use default PHP session because it might be tricky working with background process .... I would recommend session_set_save_handler http://www.php.net/manual/en/function.session-set-save-handler.php for a DB bases session

There is a good example here http://www.php.net/manual/en/function.session-set-save-handler.php#96305

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, i think i would save session data in other source.
0

Call

string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )

with $maxlen =0;

In filename you can give the url. In that url pass session id and in the called script set session id using session_id() and then call session_start().

Make sure that called script returns at least 520 dummy characters using flush() and ob_flush(), so that calling script do not wait.

Comments

0

The whole point behind a "session" is so that a user client can connect to the server multiple times in a "state-less" fashion, yet still maintain "state" like one single connection. "Session" data is shared between multiple connections from the same user client.

When you spawn off a background process on the server, whether or not you're using PHP, the "session" no longer has any real meaning. The user might even shut his client machine off with no effect on the server background process.

With that in mind, using Cookies as suggested elsewhere is totally useless. Cookies are saved on the client machine, and the background process will have Zero access to it.

If there is client information that your background process will need, then the calling process needs to pass it to the background process somehow, either as some kind of parameter or as some kind of a data file.

I would recommend saving the "$_SESSION" variable as a Json-encoded data string to a temporary file. The background process can read that file, Json-decode it back into an array, then use it just as if it were still a $_SESSION. Then remove the temporary file.

Comments

-1
$_COOKIE['PHPSESSID'] = 'user_session_id';//Transfer parameters through $GLOBALS['argv']
session_start();

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.