Request for a given time?

Is there a way to request a given time from a PHP script?

I want to write a PHP script that takes an identifier and then queries the MySQL database to find out if there is a match. In the case when another user has not yet downloaded their match, so I try to query until I find a match or pass 5 seconds, after which I will return 0.

In pseudo-code, this is what I was thinking about, but it doesn't seem like a good method, since I read the loop requests, it is not good practice.

$id_in = 123;
time_c = time();
time_stop = time + 5; //seconds

while(time_c < time_stop){
     time_c = time()
     $result = mysql_query('SELECT * WHERE id=$id_in');
}
0
source share
2 answers

It looks like your requirement is to poll some table until a row with a specific identifier appears. To do this, you need the following query:

SELECT some-column, another column FROM some-table WHERE id=$id_in

(Pro tip: SELECT * .)

, , . .

- sleep(5), , . , .

- , . php , , , , . , php , . , . . , , MySQL. , , . (, , ?) , , , .

, .
 usleep(500000);

. MySQL . php , , .

+1

. , GET_LOCK() PHP Semaphore.

,

SELECT GET_LOCK("id-123", 0);

:

SELECT GET_LOCK("id-123", 5) as locked, entities.*
  FROM entities WHERE id = 123;

, TRIGGER - , .

0

All Articles