original_string: public function get_lock($resource, $timeout, $maxlifetime = 86400) {
          $giveuptime = time() + $timeout;
  
          $hash = md5($this->type . '_' . $resource);
          $lockdir = $this->lockdirectory . '/' . substr($hash, 0, 2);
  
          if (!check_dir_exists($lockdir, true, true)) {
              return false;
          }
  
          $lockfilename = $lockdir . '/' . $hash;
  
          $filehandle = fopen($lockfilename, "wb");
  
          // Could not open the lock file.
          if (!$filehandle) {
              return false;
          }
  
          do {
              // Will block on windows. So sad.
              $wouldblock = false;
              $locked = flock($filehandle, LOCK_EX | LOCK_NB, $wouldblock);
              if (!$locked && $wouldblock && $timeout > 0) {
                  usleep(rand(10000, 250000)); // Sleep between 10 and 250 milliseconds.
              }
              // Try until the giveup time.
          } while (!$locked && $wouldblock && time() < $giveuptime);
  
          if (!$locked) {
              fclose($filehandle);
              return false;
          }
          if ($this->verbose) {
              fwrite($filehandle, $this->get_debug_info());
          }
          return new lock($filehandle, $this);
      }
code: public function get_lock($resource, $timeout, $maxlifetime = 86400) {
          $giveuptime = time() + $timeout;
  
          $hash = md5($this->type . '_' . $resource);
          $lockdir = $this->lockdirectory . '/' . substr($hash, 0, 2);
  
          if (!check_dir_exists($lockdir, true, true)) {
              return false;
          }
  
          $lockfilename = $lockdir . '/' . $hash;
  
          $filehandle = fopen($lockfilename, "wb");
  
          // Could not open the lock file.
          if (!$filehandle) {
              return false;
          }
  
          do {
              // Will block on windows. So sad.
              $wouldblock = false;
              $locked = flock($filehandle, LOCK_EX | LOCK_NB, $wouldblock);
              if (!$locked && $wouldblock && $timeout > 0) {
                  usleep(rand(10000, 250000)); // Sleep between 10 and 250 milliseconds.
              }
              // Try until the giveup time.
          } while (!$locked && $wouldblock && time() < $giveuptime);
  
          if (!$locked) {
              fclose($filehandle);
              return false;
          }
          if ($this->verbose) {
              fwrite($filehandle, $this->get_debug_info());
          }
          return new lock($filehandle, $this);
      }
code_tokens: public function get_lock ( $ resource , $ timeout , $ maxlifetime = 86400 ) { $ giveuptime = time ( ) + $ timeout ; $ hash = md5 ( $ this -> type . '_' . $ resource ) ; $ lockdir = $ this -> lockdirectory . '/' . substr ( $ hash , 0 , 2 ) ; if ( ! check_dir_exists ( $ lockdir , true , true ) ) { return false ; } $ lockfilename = $ lockdir . '/' . $ hash ; $ filehandle = fopen ( $ lockfilename , "wb" ) ; // Could not open the lock file. if ( ! $ filehandle ) { return false ; } do { // Will block on windows. So sad. $ wouldblock = false ; $ locked = flock ( $ filehandle , LOCK_EX | LOCK_NB , $ wouldblock ) ; if ( ! $ locked && $ wouldblock && $ timeout > 0 ) { usleep ( rand ( 10000 , 250000 ) ) ; // Sleep between 10 and 250 milliseconds. } // Try until the giveup time. } while ( ! $ locked && $ wouldblock && time ( ) < $ giveuptime ) ; if ( ! $ locked ) { fclose ( $ filehandle ) ; return false ; } if ( $ this -> verbose ) { fwrite ( $ filehandle , $ this -> get_debug_info ( ) ) ; } return new lock ( $ filehandle , $ this ) ; }
docstring: Get a lock within the specified timeout or return false.
  @param string $resource - The identifier for the lock. Should use frankenstyle prefix.
  @param int $timeout - The number of seconds to wait for a lock before giving up.
  @param int $maxlifetime - Unused by this lock type.
  @return boolean - true if a lock was obtained.
docstring_tokens: Get a lock within the specified timeout or return false .