title: PHP MySQLi Lock Tables Query Sometimes Does Not Complete
body: <p>I am attempting to lock some tables while running some code and unlocking the tables when I am done.</p>
  
  <p>Process:</p>
  
  <ol>
  <li>Run Lock Tables MySQL Query.</li>
  <li>Run some PHP Code.</li>
  <li>Run Unlock Tables MySQL Query.</li>
  </ol>
  
  <p>While running this process, 9 times out of 10 everything runs perfectly. Sometimes, when I run my query no response comes back from MySQL and PHP just waits for a response. Since no response happens, I never get to steps 2 or 3 and the table stays locked indefinitely. I am running the exact same Lock Tables Query in every single attempt.</p>
  
  <p>I am locking Numerous tables. Below is a similar example to my actual table query. I am using the same table multiple times with different aliases based on the queries I am attempting to prevent from accessing the tables.</p>
  
  <pre><code>$sql = "LOCK TABLES table1 as t1 WRITE
                      , table2 as t2 WRITE
                      , table3 WRITE
                      , table2 WRITE
                      , table4 WRITE
                      , table1 WRITE
                      , table5 WRITE
                      , table5 as t5 WRITE
                      , table6 as t6 WRITE
                      , table7 as t7 WRITE
                      , table7 WRITE
                      , table8 as t8 WRITE
                      , table9 t9 WRITE
                      , table10 t10 WRITE
                      , table11 t11 WRITE
                      , table12 WRITE;";
  
  $this-&gt;mysqli = new mysqli(
      $this-&gt;credentials-&gt;server
      , $this-&gt;credentials-&gt;user
      , $this-&gt;credentials-&gt;password
      , $this-&gt;credentials-&gt;database
  );
  
  try{
      error_log('before first attempt lock tables '.$sql);
      $this-&gt;mysqli-&gt;query($sql);
      error_log('after first attempt lock tables');
  } catch (Exception $e){
      error_log('Error locking tables: '.$e-&gt;getMessage());
  }
  
  error_log('After try catch.');
  if($this-&gt;mysqli-&gt;error){
      error_log('lock table error: '.$this-&gt;mysqli-&gt;error);
  }
  </code></pre>
  
  <p>When the process fails, I see "before first attempt lock tables" in my PHP  Error log. I do not see any of the other error_log() calls. After some checking, I determined it is because PHP has not received a response from MySQL.</p>
  
  <p>I never get into the Catch Exception, since MySQL is not returning an error. MySQL is not returning anything unless I manually kill the MySQL Lock Tables Process.</p>
  
  <p>If I don't kill the process, the PHP code never stops waiting for a response from mysql.</p>