简体   繁体   English

php / mysql不能同时运行两次相同的文件

[英]php/mysql can't run same file twice at the same time

I'm trying to make a "robot" do some data processing but can't figure out how to run the same file twice and speed up the processing with multiple processes of same file. 我正在尝试使“机器人”进行一些数据处理,但无法弄清楚如何两次运行相同的文件并加快同一文件的多个进程的处理速度。

My code: 我的代码:

while($stop != 1){

    $result = $mysqli->query("SELECT * FROM `data` WHERE `state` = 'nothing' ORDER BY `id` DESC");
    $row = $result->fetch_assoc();

    if(empty($row)){
        echo $i." stop";
        $stop = 1;
    }else{
        echo "do ".$i."<br/>";
        $mysqli->query("UPDATE `data` SET `state` = 'done' WHERE `id` = '{$row['id']}'");
    }

    $i++;
}

Pretty simple, right? 很简单,对吧?

The file continues until there is no more state = 'nothing' in the database and it works fine with one file... 该文件继续进行,直到数据库中不再有state ='nothing'为止,并且对一个文件运行良好...

It just goes like: 就像这样:

do 1
do 2
do 3
do 4
do 5
do 6
do 7

(There are like 3000 rows in the database) (数据库中大约有3000行)

But if I run the same file second time it doesn't do anything and just waits for the other file to finish and then just writes "1 stop" meaning it did nothing even if I started the files at the same time. 但是,如果我第二次运行同一文件,它什么也不做,只是等待另一个文件完成,然后只写“ 1 stop”,这意味着即使我同时启动文件也没有任何作用。

I noticed if I start the both files at the same and cancel the execution of the first file - the second file just starts from 1 id even through like 500 of lines are already state = 'nothing'. 我注意到如果我同时启动两个文件并取消了第一个文件的执行,那么即使有500行已经是state ='nothing',第二个文件也只能从1 id开始。

It got me thing now... is this a php or mysql problem? 现在让我明白了...这是php还是mysql问题? How can I make one file runned twice process different data and not hang up like this? 如何使运行两次的一个文件处理不同的数据而不像这样挂断?

CentOS release 6.6 (Final) CentOS版本6.6(最终版)

PHP 5.3.28 (cli) (built: Jul 21 2014 12:19:25) PHP 5.3.28(CLI)(构建于2014年7月21日12:19:25)

+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| protocol_version        | 10                           |
| slave_type_conversions  |                              |
| version                 | 5.5.38                       |
| version_comment         | MySQL Community Server (GPL) |
| version_compile_machine | x86_64                       |
| version_compile_os      | Linux                        |
+-------------------------+------------------------------+

try to use different query ex: 尝试使用其他查询,例如:

localhost/a.php?process=1 本地主机/a.php?进程= 1

localhost/a.php?process=2 本地主机/a.php?process=2

this will make your file run twice in the same time 这将使您的文件同时运行两次

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM