title: How can I run two sql queries in parallel using PHP/SQL?
body: <p>Is it possible to start two sql queries so that they run concurrently?</p>
  
  <p>In a php file, I am performing two queries on a <code>Postgresql</code> database. Using the values returned from the first two queries, I then perform a third query.</p>
  
  <pre><code>function one(){ 
     $query = pg_query($con, $sql);                               
     $a = pg_fetch_result($query, 0, 0);  
     return $a;
  }
  function two(){        
     $query = pg_query($con, $sql);                            
     $b = pg_fetch_result($query, 0, 0);  
     return $b;
  }
  
  function three($a, $b){ 
     //$a + $b used to construct query $sql
     $query = pg_query($con, $sql);                               
     $c = pg_fetch_result($query, 0, 0); 
     return $c;
  }
  </code></pre>
  
  <p>Is it possible to run functions <code>one</code> and <code>two</code> at the same time? One other approach that I considered was to make <code>a</code> and <code>b</code> global variables and to initially set them to <code>null</code>. Then, instead of functions <code>one</code> and <code>two</code> returning any values, they just set the values of <code>a</code> and <code>b</code> when they are complete. I then constantly check to see if <code>a</code> and <code>b</code> are not null, and when this is true, call function <code>three</code>. </p>
  
  <p>Searching on this topic I read about <code>pcntl</code> but I'm unclear if this is the best way of performing a calculation of this type.<code>pcntl</code> is not installed on my webhosting service (WebFaction), by default.</p>
  
  <p>Another approach might be to use <a href="http://www.php.net/manual/en/function.pg-send-query-params.php" rel="nofollow">pg_send_query_params()</a> which enables me to perform the same query using different parameters which is probably quicker than my original approach.</p>