Jump to content

concurrency issues


naitsir

Recommended Posts

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

..}

}

?>

Link to comment
Share on other sites

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). :shrug:

 

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  :-\

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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??

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.