PHP requests to call a method one after another, and if the processing of the first request does not end, what will be the impact of the second call?

background scheduled task polling calls a method, which is executed once per second. It mainly takes dozens of data loops from the database for processing. It takes about 3 seconds to finish the whole cycle. If the polling is not finished for the first time, what is the effect of the next call? How is it an execution process, will it be blocked? Or do I need to use a file lock and release it when the loop is finished

Php
Mar.31,2021

does not finish execution for the first time, and the call will be executed again. Because different processes reprocess, this is definitely not the result you want, so you need to dispose of it yourself, either file lock or redis lock.


this question can be considered, how can it be realized when multiple users like the article at the same time? Because the process of operation is generally to take values, modify, store values. If they all operate at the same time, regardless of error and no other processing, then the process everyone operates is to get 0, modify 0 + 1, and save 1.


first of all, this problem is essentially a problem of concurrent processing of mutually exclusive resources

  1. the easiest way to solve your question is to start a process, process it in turn, and then iterate

pseudo code:

<?php
-sharp do.php
while(true) {
    $rows = mysql_fetch_rows();
    foreach ($rows as $row) {
        do_something(row);
        usleep(500000);
    }
    //todo record log
    sleep(1);
}

php do.php
  1. Advanced processing: you can learn multi-process, distributed lock correlation to handle resource mutual exclusion (file lock, redis lock, zookeeper lock are all fine);

of course, using mysql's exclusive lock directly can also easily solve a mutual exclusion problem, but it will bring more other problems

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b563-2bad1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b563-2bad1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?