FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Problem getting session through CURL
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Problem getting session through CURL [message #173379] Wed, 06 April 2011 20:07 Go to next message
Tobiah is currently offline  Tobiah
Messages: 30
Registered: April 2011
Karma: 0
Member
I have a web page that needs to load another web page
through CURL, and then use the content of that transfer
for something else. I'm setting the PHPSESSID cookie
successfully in the call to curl. I can print out the
$_COOKIE array from the curl loaded page, and see that
it is being set properly. The problem I'm having, is
that if I call session_start() in that curl loaded page,
it just hangs, and curl never returns. If I call session_destroy()
first from the parent script, the curl call returns, but
even though I can see that the PHPSESSID cookie is still
set with the same value as the parent script, and call session_start()
from the curl page, the $_SESSION
is empty. I tried explicitly setting the sessid with session_id()
but that didn't make any difference.

I've "highjacked" my own session in this way on purpose
to make session data available on a different server, Now
I'm doing the same thing on the same server, and I get
that hanging problem. I would have thought that this
would be like loading a frameset; you can have multiple
requests running at the same time under the same session id.

Maybe this has something to do with the fact that the curl
call is actually running in the same process as the parent
page?

Thanks!,

Tobiah
Re: Problem getting session through CURL [message #173389 is a reply to message #173379] Thu, 07 April 2011 07:19 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 06/04/2011 22:07, Tobiah escribió/wrote:
> I have a web page that needs to load another web page
> through CURL, and then use the content of that transfer
> for something else. I'm setting the PHPSESSID cookie
> successfully in the call to curl. I can print out the
> $_COOKIE array from the curl loaded page, and see that
> it is being set properly. The problem I'm having, is
> that if I call session_start() in that curl loaded page,
> it just hangs, and curl never returns.

Are you by chance running both scripts on the same server? If the first
script is already using the session file, the file will be kept locked
until its released and the second script will wait forever. You need to
call session_write_close() in the first script before you call the
second one.



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: Problem getting session through CURL [message #173396 is a reply to message #173389] Thu, 07 April 2011 16:48 Go to previous message
Tobiah is currently offline  Tobiah
Messages: 30
Registered: April 2011
Karma: 0
Member
On Thu, 07 Apr 2011 09:19:24 +0200, Álvaro G. Vicario wrote:

> El 06/04/2011 22:07, Tobiah escribió/wrote:
>> I have a web page that needs to load another web page through CURL, and
>> then use the content of that transfer for something else. I'm setting
>> the PHPSESSID cookie successfully in the call to curl. I can print out
>> the $_COOKIE array from the curl loaded page, and see that it is being
>> set properly. The problem I'm having, is that if I call
>> session_start() in that curl loaded page, it just hangs, and curl never
>> returns.
>
> Are you by chance running both scripts on the same server? If the first
> script is already using the session file, the file will be kept locked
> until its released and the second script will wait forever. You need to
> call session_write_close() in the first script before you call the
> second one.

Yeah, I was trying to set a cookie in the curl call so that
I'd have the same session as the parent script (yes, the same server).
Thanks for pointing me to session_write_close(). That is exactly what
I needed.

Toby
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to test if .php is using FastCGI?
Next Topic: Lookup zip by IP address
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 05:35:08 GMT 2024

Total time taken to generate the page: 0.03203 seconds