Re: Any bright solution for my problem?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I can think of a few things off the top of my head. Not that any are perfect solutions.

The first and most obvious would be to select your 50 record set into memory, update the records as "processing", then deliver the data, then update the records as "used".

Or, have another table with one record and one field. When a script starts, it updates the field to indicate a running state. When it finishes it changes the field to indicate an idle state. So whenever a script runs, it checks the field to see if another script that is running. You may be able to get the same affect by locking the table, which would probably be better, but I don't know if you can have the table locked for a minute (no updates).

Another possible option is to use limit intervals in your query. You are probably already using limit to restrict your results to 50 records. You can use the same concept as above, but use the field to indicate which set of 50 to return next. Whatever number is in the field, you just multiply by 50 to get your limit range. So a 0 (zero) would give you LIMIT (0*50),50, a 1 would give you (1*50),50, a 2 would give you (2*50),50, etc. Then your queries can overlap.

Of course, none of these work for a multi delivery setup since you can't track which records have been delivered to which url. For that, you may want to select your entire database into a temporary table, or just the unique IDs, then use the temp table for processing using something like the first idea.

To take a technique from monitoring shell scripts I've written, have the script do the timing. Get a time stamp when the script starts. When it finishes its run it gets an end time. If the time difference is more than a minute, it immediately runs again, otherwise it "sleeps" for the remaining differential. This assures that the script won't trip over a copy of itself. Basically you are setting up a dependency, you don't want script x to run until script y is finished, but in this case x and y are the same script.


On Dec 22, 2004, at 5:20 AM, QT wrote:

Dear Sirs,

I have a database with thousands records. And every minutes I am selecting
50 rows from that database and send some data to another web url according
sellected 50 rows.


Whenever, my script finish job in one minute, I have no problem. Because
after each transaction, I am uptading one of the rows field as a "uesd".


BUT! if my script can not finish sending data to another url due to low
speed connection or such a problem. On the next minute, same script runs
automaticlay and sellecting another 50 rows which are not marked by "used".


In this case, some times these two running acripts are sellecting same rows
due to, old one haven't marked as a "used" for sellected rows.


Is there any way, to put flag or something like that, when sellecting rows
with php and mysql?


Best Regards

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux