dsa1234569 2012-11-03 19:18
浏览 27
已采纳

繁忙的PHP脚本使其他脚本变慢 - 如何?

On my localserver, XAMPP environment, I'm running a test PHP script that takes 20 seconds to run, but uses only 2MB of memory and 10% CPU.

When I open a new window and run the same script at the same time as the first, it takes over 30 seconds for both scripts to finish.

--The script is a simple for loop that writes to mysql DB, InnoDb, 200 times.

Shouldn't the script take the same amount of time, but use more system resources?

As in, scale linearly.

Why is this?

  //the code in all its glory-- Post extends a CRUD class
  // These are the values to be saved:
   $values = array(
  'id' => '',
  'content' => 'This is the VALUE'
                 );
  //And the action. I know-Saving Mysql in a loop is a no-no-- 
    //for demonstration only  
   for($i=0; $i<250; $i++){

   $object = new Post($values); //instantiate the Post Class with values
   $object->create($values);   //save the values to the Db. The end
                           }

20 seconds.

  • 写回答

1条回答 默认 最新

  • douxin20081125 2012-11-03 19:20
    关注

    Seems like it is creating a lock on the DB. So 1 can not complete before the other one does.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?