[PHP] Ajax (xmlHttpRequest) and session_start() problem.
I Have an very strange problem. When i execute an very simple Ajax request to an PHP script wich just print one line and i put an sleep(20) infront of it, it works perfectly when i refresh the page. BUT.. When i put session_start() at the top, i can't refresh the page anymore. It won't refresh untill the server responed. When i remove the session_start(), i can refresh anytime i want. Is this a know problem? Does someone knows an solution? Thx for the help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Ajax (xmlHttpRequest) and session_start() problem.
On Wed, 2006-05-17 at 10:11, Mathijs wrote: > I Have an very strange problem. > > When i execute an very simple Ajax request to an PHP script wich just > print one line and i put an sleep(20) infront of it, it works perfectly > when i refresh the page. > > BUT.. > When i put session_start() at the top, i can't refresh the page anymore. > It won't refresh untill the server responed. > > When i remove the session_start(), i can refresh anytime i want. > > Is this a know problem? > Does someone knows an solution? PHP sessions use locking to avoid race conditions. So you sleep for 20 seconds keeps the lock for just as long, this has the effect of blocking all other scripts for the same session. To avoid this, grab the session data you need, and close the session as fast as possible. Additionally, it's probably a very bad idea to keep the web server waiting for 20 seconds for no good reason. Why not have your javascript do the waiting? Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Ajax (xmlHttpRequest) and session_start() problem.
Robert Cummings wrote: On Wed, 2006-05-17 at 10:11, Mathijs wrote: I Have an very strange problem. When i execute an very simple Ajax request to an PHP script wich just print one line and i put an sleep(20) infront of it, it works perfectly when i refresh the page. BUT.. When i put session_start() at the top, i can't refresh the page anymore. It won't refresh untill the server responed. When i remove the session_start(), i can refresh anytime i want. Is this a know problem? Does someone knows an solution? PHP sessions use locking to avoid race conditions. So you sleep for 20 seconds keeps the lock for just as long, this has the effect of blocking all other scripts for the same session. To avoid this, grab the session data you need, and close the session as fast as possible. Additionally, it's probably a very bad idea to keep the web server waiting for 20 seconds for no good reason. Why not have your javascript do the waiting? Cheers, Rob. This whas just an test example i talked about. irl, i have an script that does an search on the server for texts in files. This search goes through an ajax request. The page that is requested uses $_SESSION. Therefore i need session_start(). This search can take a while, and if i want to refresh the page, because i want to have an other search or whatever, i just can't. This because, for some reason, when session_start() gets called, it locks the refreshing capeabileties of the browser. Also, you say to close the session, mabye a stupid question, but how If you need more info, just ask :).. Thx for the quick reply :). Kind Regards, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Ajax (xmlHttpRequest) and session_start() problem.
session_write_close(); Ex: session_start(); $asdf = $_SESSION; //-- get all datas session_write_close(); //-- close session on Wednesday 17 May 2006 16:36, Mathijs wrote: > Robert Cummings wrote: > > On Wed, 2006-05-17 at 10:11, Mathijs wrote: > >> I Have an very strange problem. > >> > >> When i execute an very simple Ajax request to an PHP script wich just > >> print one line and i put an sleep(20) infront of it, it works perfectly > >> when i refresh the page. > >> > >> BUT.. > >> When i put session_start() at the top, i can't refresh the page anymore. > >> It won't refresh untill the server responed. > >> > >> When i remove the session_start(), i can refresh anytime i want. > >> > >> Is this a know problem? > >> Does someone knows an solution? > > > > PHP sessions use locking to avoid race conditions. So you sleep for 20 > > seconds keeps the lock for just as long, this has the effect of blocking > > all other scripts for the same session. To avoid this, grab the session > > data you need, and close the session as fast as possible. Additionally, > > it's probably a very bad idea to keep the web server waiting for 20 > > seconds for no good reason. Why not have your javascript do the waiting? > > > > Cheers, > > Rob. > > This whas just an test example i talked about. > irl, i have an script that does an search on the server for texts in files. > > This search goes through an ajax request. > The page that is requested uses $_SESSION. > Therefore i need session_start(). > > This search can take a while, and if i want to refresh the page, because > i want to have an other search or whatever, i just can't. > This because, for some reason, when session_start() gets called, it > locks the refreshing capeabileties of the browser. > > Also, you say to close the session, mabye a stupid question, but how > > If you need more info, just ask :).. > > Thx for the quick reply :). > > Kind Regards, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Ajax (xmlHttpRequest) and session_start() problem.
Thank you very much :D. Ill just create an class which will handle this :). It works like a charm.. Thx. Thomas Munz wrote: session_write_close(); Ex: session_start(); $asdf = $_SESSION; //-- get all datas session_write_close(); //-- close session on Wednesday 17 May 2006 16:36, Mathijs wrote: Robert Cummings wrote: On Wed, 2006-05-17 at 10:11, Mathijs wrote: I Have an very strange problem. When i execute an very simple Ajax request to an PHP script wich just print one line and i put an sleep(20) infront of it, it works perfectly when i refresh the page. BUT.. When i put session_start() at the top, i can't refresh the page anymore. It won't refresh untill the server responed. When i remove the session_start(), i can refresh anytime i want. Is this a know problem? Does someone knows an solution? PHP sessions use locking to avoid race conditions. So you sleep for 20 seconds keeps the lock for just as long, this has the effect of blocking all other scripts for the same session. To avoid this, grab the session data you need, and close the session as fast as possible. Additionally, it's probably a very bad idea to keep the web server waiting for 20 seconds for no good reason. Why not have your javascript do the waiting? Cheers, Rob. This whas just an test example i talked about. irl, i have an script that does an search on the server for texts in files. This search goes through an ajax request. The page that is requested uses $_SESSION. Therefore i need session_start(). This search can take a while, and if i want to refresh the page, because i want to have an other search or whatever, i just can't. This because, for some reason, when session_start() gets called, it locks the refreshing capeabileties of the browser. Also, you say to close the session, mabye a stupid question, but how If you need more info, just ask :).. Thx for the quick reply :). Kind Regards, --- avast! Antivirus: Inbound message clean. Virus Database (VPS): 0620-0, 05/15/2006 Tested on: 5/17/2006 6:37:16 PM avast! - copyright (c) 1988-2006 ALWIL Software. http://www.avast.com --- avast! Antivirus: Outbound message clean. Virus Database (VPS): 0620-0, 05/15/2006 Tested on: 5/17/2006 6:38:04 PM avast! - copyright (c) 1988-2006 ALWIL Software. http://www.avast.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php