2

After doing some research on this issue, I couldn't find any satisfying fix.

The problem is: I'm performing a GET request programmatically. The request itself works fine and the requested page does so as well. I need to check for a valid login before performing any other actions within the requested page, therefore I've sent the Session cookie to receive the Session's ID, which also works fine. But as soon as I invoke *session_start( )*, the request exceeds the execution time limit of 60 seconds. Accessing the requested page directly works fine, though.

This might be an important remark: The requesting page also uses Sessions for the same checkings.

The reason why I want the requested page to be "remote" / "standalone" / however you want to call it, is that I want to make it accessible via AJAX as well. I suppose simply including the file and check whether the file is directly called would work as well, but I've done it now this way and am almost satisfied with it.

My question now is: Can anybody tell me why session_start rather crashes my script? And does somebody know a patch for this?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • I do not understand what you mean by "check" as opposed to calling a script directly. How are you performing that check? – Pekka Aug 15 '11 at 15:14
  • Well, this check I do by reading data stored in the session, then connecting to the database to verify the user. The checking isn't actually the important point and it's not meant to be opposed. The whole thing is actually to provide this single file for two different ways of calling. – DarkDragon1993 Aug 15 '11 at 15:35
  • I still don't understand. `The request itself works fine and the requested page does so as well.` does that mean you do not always perform the check? Does the requested page not do a `session_start()`? Maybe you should show some code – Pekka Aug 15 '11 at 15:37
  • As I said, the check isn't the point since it hasn't even been implemented on the requested page. What I exaclty mean, is: Calling the page directly by it's URL works fine, but calling it via the PHP script let's it exceed the 60 seconds time limit. The spare code is: `` – DarkDragon1993 Aug 15 '11 at 15:40
  • Okay. So you are making a GET request, i.e. it's prefixed by `http://`, to your own local server, correct? – Pekka Aug 15 '11 at 15:43
  • I'm using fsockopen to perform the request, though I'm leaving the `http://` prefix away. And yes, it is on my own local server. – DarkDragon1993 Aug 15 '11 at 15:45

1 Answers1

2

Sessions are blocking in PHP, meaning that if you run two requests on the same host that use the same session, one of them will be blocked (waiting) until the first one has finished.

In your situation, if your programmatic GET request uses the client's session ID, it could be that the two scripts are blocking each other - and because the one is calling the other, the "child" script will wait indefinitely.

It's hard to suggest a solution without knowing your project, but it feels to me it isn't right to make a programmatic GET request with the client's session ID. Maybe you can change that behaviour.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Well, that really was the problem. Destroying the session before doing the request solved the problem. Thank you, and thank you for your advice to change the behaviour. Although I might not really necessarily need a programmatic request here, I'll soon need it for another experiment. – DarkDragon1993 Aug 15 '11 at 15:54