문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top