简体   繁体   English

PHP睡眠迫使查询变慢

[英]PHP sleep forces slow queries

im experiencing a problem where i have 我遇到一个我有的问题

one insert then sleep(25) then second insert. 一个插入,然后sleep(25),然后第二个插入。

datetime from first insert ALWAYS matches the datetime from second insert. 第一个插入的datetime总是匹配第二个插入的datetime。

The problem is that both inserts happen at the same time after sleep. 问题是两个插入都在睡眠后同时发生。 So i placed a condition for the second insert that checks for the first insert but the problem is there. 所以我为第二个插入放置了一个条件,该条件检查了第一个插入,但是问题就在那里。 I am using Zend DB select. 我正在使用Zend DB select。

Notes: I have also tried live()->query($sql) and have the same results 注意:我也尝试过live()-> query($ sql)并得到相同的结果

            $sql = "insert into leads_verify
            (customer, lead_id,dt)
            values
            ('2'
            ,'111'
            ,'". date("Y-m-d H:i:s")."')";

            $queryResult = Db::live()->exec($sql);

            if($queryResult <> '5' ){
                sleep(24);
            }

            $sql2 = "insert into leads_verify
            (customer, lead_id,dt)
            values
            ('3'
            ,'222'
            ,'". date("Y-m-d H:i:s")."')";

                          $queryResult = Db::live()->exec($sql2);

The datetime of insertion is always the same for both. 两者的插入日期时间始终相同。 Any ideas? 有任何想法吗?

Are you using transactions in Zend? 您在Zend中使用交易吗?

then you need to commit your statements: 那么您需要提交您的声明:

Db::live()->commit();

and by the way: 顺便说一下:
if the dt field is of the type DATE ore DATETIME , you can use Now() instead of '". date("Ymd H:i:s")."' 如果dt字段的类型为DATE DATETIME ,则可以使用Now()代替'". date("Ymd H:i:s")."'

The solution i used was to connect using mysql_query and run the sql that way. 我使用的解决方案是使用mysql_query连接并以这种方式运行sql。 Thanks aLL 谢谢你

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

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