title: PHP, wake up process which is sleeping
body: <p>I have two PHP scripts which are running at the same time. One of them (<code>SleepingScript.php</code>) calls the <code>sleep</code> function. The other script (<code>WakeScript.php</code>) should be able to wake up the sleeping script if necessary.</p>
  
  <p>How can I achieve this?</p>
  
  <p>Here is some code that explains better the situation.</p>
  
  <h2>SleepingScript.php</h2>
  
  <pre><code>&lt;?php
     $myPid = getmypid();
     /* save $myPid to database or file */
     sleep( 120 );
     /* other statements executed after 2 minutes or when woken up by WakeScript */
  ?&gt;
  </code></pre>
  
  <h2>WakeScript.php</h2>
  
  <pre><code>&lt;?php
      /* ... */
      if( $wakeUpNeeded ) {
        $pid = readSavedPid();
        wake( $pid );
      }
  ?&gt;
  </code></pre>