title: Make PHP wait for python script to complete
body: <p>I'm using the exec() command in PHP to run a python script that will produce some output. This python script queries a rather large PostgreSQL database, so it does take a second or two to execute. Here is my code:</p>
  
  <p>test.php   </p>
  
  <pre><code>&lt;?php
  $output = exec('/usr/local/bin/python2.7 test.py', $output); 
  var_dump($output);
  ?&gt;
  </code></pre>
  
  <p>test.py</p>
  
  <pre><code>import nfldb
  
  
  db = nfldb.connect()
  q = nfldb.Query(db)
  
  q.game(season_year=2012, season_type='Regular')
  for pp in q.sort('passing_yds').limit(10).as_aggregate():
      print pp.player, pp.passing_yds
  </code></pre>
  
  <p>All of the code works correctly as verified by running the python script from the command line and putting a test "print 10" in the python script to make sure the php script was working.</p>
  
  <p>I'm pretty sure because it takes a few seconds to execute the script that PHP isn't waiting for the output correctly. I tried the set_time_limit() function but it doesn't actually count time from exec().</p>
  
  <p>Any suggestions?</p>