naitsir Posted September 25, 2009 Share Posted September 25, 2009 hi all, i home some of you can enlighten me. (sorry for my english) this is the scenario, i have a infinite loop that is interrupted when set_time_limit reaches the limit, inside the loop performs a query to the DB. when i run the php script in firefox, i can't access to the DB from another page of firefox (phpmyadmin, another script, etc) but i can access to the DB from Internet Explorer. I need to open the DB from the same browser without the DB crash. i researched and came to the conclusion that there is not a problem of mysql DB. Have any of you have idea how fix this? I put a piece of code to give you an idea of how it works <?php set_time_limit(60); while( true ){ ..$sSql = "select state, value1, value... from table" ..$res = mysql_query($sSql,$conn); ..while ($row = mysql_fetch_assoc($res)){ ....//do something with the result ..} } ?> Quote Link to comment Share on other sites More sharing options...
naitsir Posted September 28, 2009 Author Share Posted September 28, 2009 any of you happens to how to solve this?? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 28, 2009 Share Posted September 28, 2009 i can't access to the DB from another page of firefoxWhat exactly is it doing when you try it? DB crashWhat DB crash? All you stated was that you can't access the DB. Quote Link to comment Share on other sites More sharing options...
naitsir Posted September 28, 2009 Author Share Posted September 28, 2009 hi PFMaBiSmAd, i can't access to the DB from another page of firefox What exactly is it doing when you try it? when i run the script with the infinite loop in Firefox, then i try to access to the DB from another window of firefox, but the DB is blocked, but I can access to the DB from another Browser (IE, Opera, Safari). DB crash What DB crash? All you stated was that you can't access the DB. ok, sorry, I made a mistake in expressing, i'm a beginner in english :-\ Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 28, 2009 Share Posted September 28, 2009 I suppose the Web server is seeing the requests fromthe same browser as a single instance. Since you have an infinite loop running it doesn't have any available resources for that instance. But, it may be seeing the use of different browsers as different instances. A better question is why in the world would you want to have an infinite loop running? There is most definitely a beeter way to accomplish what you are trying to do. Quote Link to comment Share on other sites More sharing options...
naitsir Posted September 28, 2009 Author Share Posted September 28, 2009 I suppose the Web server is seeing the requests fromthe same browser as a single instance. Since you have an infinite loop running it doesn't have any available resources for that instance. But, it may be seeing the use of different browsers as different instances. maybe you are right, i also thought this, I researched about no persistent connections, threads creation, but i can't find a feasible solution. how do i create an instance completely different for this script?? A better question is why in the world would you want to have an infinite loop running? There is most definitely a beeter way to accomplish what you are trying to do well, this is an implementation of COMET, the idea is to send alerts to the client without a request http://en.wikipedia.org/wiki/Comet_%28programming%29 the user request the main page, and the conection is open, at the time the table is update, this is displayed on the user's browser without a request by the user(real-time alarms) thanks for your interest, i hope we can find a solution. regards. Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 28, 2009 Share Posted September 28, 2009 A better question is why in the world would you want to have an infinite loop running? There is most definitely a beeter way to accomplish what you are trying to do well, this is an implementation of COMET, the idea is to send alerts to the client without a request http://en.wikipedia.org/wiki/Comet_%28programming%29 the user request the main page, and the conection is open, at the time the table is update, this is displayed on the user's browser without a request by the user(real-time alarms) You should not put an infinite loop on the server code. "Comet" typically uses AJAX code. If you are using AJAX, then you should have JavaScript code ont he client side that performs a request to the server on set intervals and brings down any new content. Having infinite loops on the server is going to bring your server to a crawl with just a small number of users. And, to be honest, I'm not even sure how having an infinite loop on the server would even work. How do you populate the new data back down to the client in that model without the client making an AJAX request? Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 28, 2009 Share Posted September 28, 2009 Use database trigger, or a cron to access the page to update ect, or stop the page doing something... The code you supply is not the way to make a cron job ok. cron is a small program that can help programmers open pages, and execute applications ect ect via the time being set via the cron program.......... here a link to cron for windows http://cronw.sourceforge.net/ lynx got cron already pre installed just use it. you could also use JavaScript / ajax. Quote Link to comment Share on other sites More sharing options...
naitsir Posted September 28, 2009 Author Share Posted September 28, 2009 mjdamato You should not put an infinite loop on the server code. "Comet" typically uses AJAX code. If you are using AJAX, then you should have JavaScript code ont he client side that performs a request to the server on set intervals and brings down any new content. Having infinite loops on the server is going to bring your server to a crawl with just a small number of users..... the idea is send alerts to the client in real-time. I modified this example to my needs, supposedly works, but i have problems :S http://www.zeitoun.net/articles/comet_and_php/start i thought of using AJAX, but i try to avoid the traffic between client-server to reduce costs on cell phones mjdamato How do you populate the new data back down to the client in that model without the client making an AJAX request? check the example http://www.zeitoun.net/articles/comet_and_php/start i send javascript code to the user, this will be executed immediately. my javascript show a hidden div with the message. it works fine, the only problem is the blocking of the DB in the same browser redarrow Use database trigger, or a cron to access the page to update ect, or stop the page doing something... The code you supply is not the way to make a cron job ok. cron is a small program that can help programmers open pages, and execute applications ect ect via the time being set via the cron program.......... here a link to cron for windows http://cronw.sourceforge.net/ lynx got cron already pre installed just use it. you could also use JavaScript / ajax I've looked at the possibility of using cron or curl, but there is a problem... How do I know which users are connected (browsing on FF, IE, Opera, Safari, etc) to send alerts to your browser? and if it is possible to know which users are connected... How can I make to displayed the alerts in the client browser?? Quote Link to comment Share on other sites More sharing options...
naitsir Posted September 28, 2009 Author Share Posted September 28, 2009 as additional data, is necessary to send constant query to the DB to check if there are new data to show to the user. the only way I could think was to do an infinite loop. but this loop will only run as long as I define the variable set_time_limit (about an hour). thank you very much for your interest Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.