Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top