title: PHP- Wait until a value is stored in mySQL
body: <p>I have a PHP running that uploads a file to my server, I then do some calculations with this file with another script and upload some data (the results of the calculations) to mySQL. 
  After that, I read this data (the results of the calculations) from mySQL in this same PHP that I used to upload the file to the server.
  The problem is that I don't know how long it will take to process this file in my server, it may take 5 seconds or 2 minutes, so now I'm using a sleep(40), because most files process in less time (but not all...) to make sure the values I'm looking for in mySQL will be there, but that's not the way it should be done. 
  Is there any way to make the program wait until the values I'm looking for (the results of the calculations that are made with the file I just uploaded) are stored in mySQL? 
  Something that constantly checks if the values are there and when they do continues running the program?
  I think it may not be possible with PHP and I may need a javascript. 
  This is my code:</p>
  
  <pre><code>$uploaddir = '/opt/lampp/htdocs/stl';
  $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  $link = mysql_connect("whatever", "whatever...", "whatever...whatever");
  $nombre=basename($_FILES['userfile']['name']);
  $tamany=basename($_FILES['userfile']['size']);
  $sql="INSERT INTO `wordpress`.`uploads` (`autoinc`, `nombre`, `tamany`, `fecha` , `cantidad`) VALUES (NULL, '$nombre', '$tamany', CURRENT_TIMESTAMP , '$cantidad')";
  if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
      mysql_select_db('wordpress');
      mysql_query($sql);
      rename ( $uploadfile,$uploaddir."/".mysql_insert_id().".stl");
      $uploadfile_we=basename($uploadfile,".stl");
      $numero=mysql_insert_id();
      echo '&lt;pre&gt;';
      sleep(40);
      $sqls= "SELECT `cond` FROM `cm` WHERE `id`='$numero'";
      $result = mysql_query($sqls);
      $row = mysql_fetch_assoc($result);
      $condicion = $row['cond'];
  }
  </code></pre>
  
  <p>As you can see, a file is uploded and then I look in the database. How can I know if the database has already been updated or not? </p>