original_string: public function runSet(Set $set, $timeout = null)
      {
          foreach ($this->getServers() as $server) {
              $conn = Connection::connect($server, $timeout);
              if (!Connection::isConnected($conn)) {
                  unset($this->servers[$server]);
                  continue;
              }
  
              $this->conn[] = $conn;
          }
  
          $totalTasks = $set->tasksCount;
          $taskKeys = array_keys($set->tasks);
          $t = 0;
  
          if ($timeout !== null) {
              $socket_timeout = min(10, (int) $timeout);
          } else {
              $socket_timeout = 10;
          }
  
          while (!$set->finished()) {
              if ($timeout !== null) {
                  if (empty($start)) {
                      $start = microtime(true);
                  } else {
                      $now = microtime(true);
                      if ($now - $start >= $timeout) {
                          break;
                      }
                  }
              }
  
              if ($t < $totalTasks) {
                  $k = $taskKeys[$t];
                  $this->submitTask($set->tasks[$k]);
                  if ($set->tasks[$k]->type == Task::JOB_BACKGROUND ||
                      $set->tasks[$k]->type == Task::JOB_HIGH_BACKGROUND ||
                      $set->tasks[$k]->type == Task::JOB_LOW_BACKGROUND ||
                      $set->tasks[$k]->type == Task::JOB_EPOCH) {
                      $set->tasks[$k]->finished = true;
                      --$set->tasksCount;
                  }
  
                  ++$t;
              }
  
              $write = null;
              $except = null;
              $read = $this->conn;
              socket_select($read, $write, $except, $socket_timeout);
              foreach ($read as $socket) {
                  $resp = Connection::read($socket);
                  if (count($resp)) {
                      $this->handleResponse($resp, $socket, $set);
                  }
              }
          }
      }
code: public function runSet(Set $set, $timeout = null)
      {
          foreach ($this->getServers() as $server) {
              $conn = Connection::connect($server, $timeout);
              if (!Connection::isConnected($conn)) {
                  unset($this->servers[$server]);
                  continue;
              }
  
              $this->conn[] = $conn;
          }
  
          $totalTasks = $set->tasksCount;
          $taskKeys = array_keys($set->tasks);
          $t = 0;
  
          if ($timeout !== null) {
              $socket_timeout = min(10, (int) $timeout);
          } else {
              $socket_timeout = 10;
          }
  
          while (!$set->finished()) {
              if ($timeout !== null) {
                  if (empty($start)) {
                      $start = microtime(true);
                  } else {
                      $now = microtime(true);
                      if ($now - $start >= $timeout) {
                          break;
                      }
                  }
              }
  
              if ($t < $totalTasks) {
                  $k = $taskKeys[$t];
                  $this->submitTask($set->tasks[$k]);
                  if ($set->tasks[$k]->type == Task::JOB_BACKGROUND ||
                      $set->tasks[$k]->type == Task::JOB_HIGH_BACKGROUND ||
                      $set->tasks[$k]->type == Task::JOB_LOW_BACKGROUND ||
                      $set->tasks[$k]->type == Task::JOB_EPOCH) {
                      $set->tasks[$k]->finished = true;
                      --$set->tasksCount;
                  }
  
                  ++$t;
              }
  
              $write = null;
              $except = null;
              $read = $this->conn;
              socket_select($read, $write, $except, $socket_timeout);
              foreach ($read as $socket) {
                  $resp = Connection::read($socket);
                  if (count($resp)) {
                      $this->handleResponse($resp, $socket, $set);
                  }
              }
          }
      }
code_tokens: public function runSet ( Set $ set , $ timeout = null ) { foreach ( $ this -> getServers ( ) as $ server ) { $ conn = Connection :: connect ( $ server , $ timeout ) ; if ( ! Connection :: isConnected ( $ conn ) ) { unset ( $ this -> servers [ $ server ] ) ; continue ; } $ this -> conn [ ] = $ conn ; } $ totalTasks = $ set -> tasksCount ; $ taskKeys = array_keys ( $ set -> tasks ) ; $ t = 0 ; if ( $ timeout !== null ) { $ socket_timeout = min ( 10 , ( int ) $ timeout ) ; } else { $ socket_timeout = 10 ; } while ( ! $ set -> finished ( ) ) { if ( $ timeout !== null ) { if ( empty ( $ start ) ) { $ start = microtime ( true ) ; } else { $ now = microtime ( true ) ; if ( $ now - $ start >= $ timeout ) { break ; } } } if ( $ t < $ totalTasks ) { $ k = $ taskKeys [ $ t ] ; $ this -> submitTask ( $ set -> tasks [ $ k ] ) ; if ( $ set -> tasks [ $ k ] -> type == Task :: JOB_BACKGROUND || $ set -> tasks [ $ k ] -> type == Task :: JOB_HIGH_BACKGROUND || $ set -> tasks [ $ k ] -> type == Task :: JOB_LOW_BACKGROUND || $ set -> tasks [ $ k ] -> type == Task :: JOB_EPOCH ) { $ set -> tasks [ $ k ] -> finished = true ; -- $ set -> tasksCount ; } ++ $ t ; } $ write = null ; $ except = null ; $ read = $ this -> conn ; socket_select ( $ read , $ write , $ except , $ socket_timeout ) ; foreach ( $ read as $ socket ) { $ resp = Connection :: read ( $ socket ) ; if ( count ( $ resp ) ) { $ this -> handleResponse ( $ resp , $ socket , $ set ) ; } } } }
docstring: Run a set of tasks.
  
  @param Set $set     A set of tasks to run
  @param int $timeout Time in seconds for the socket timeout. Max is 10 seconds
  
  @see MHlavac\Gearman\Set, MHlavac\Gearman\Task
docstring_tokens: Run a set of tasks .