original_string: public static function send($socket, $command, array $params = array())
      {
          if (!isset(self::$commands[$command])) {
              throw new Exception('Invalid command: ' . $command);
          }
  
          $data = array();
          foreach (self::$commands[$command][1] as $field) {
              if (isset($params[$field])) {
                  $data[] = $params[$field];
              }
          }
  
          $d = implode("\x00", $data);
  
          $cmd = "\0REQ" . pack(
              'NN',
              self::$commands[$command][0],
              self::stringLength($d)
          ) . $d;
  
          $cmdLength = self::stringLength($cmd);
          $written = 0;
          $error = false;
          do {
              $check = @socket_write($socket,
                                     self::subString($cmd, $written, $cmdLength),
                                     $cmdLength);
  
              if ($check === false) {
                  if (socket_last_error($socket) == SOCKET_EAGAIN or
                      socket_last_error($socket) == SOCKET_EWOULDBLOCK or
                      socket_last_error($socket) == SOCKET_EINPROGRESS) {
                      // skip this is okay
                  } else {
                      $error = true;
                      break;
                  }
              }
  
              $written += (int) $check;
          } while ($written < $cmdLength);
  
          if ($error === true) {
              $errno = socket_last_error($socket);
              $errstr = socket_strerror($errno);
              throw new Exception(
                  "Could not write command to socket ($errno: $errstr)"
              );
          }
      }
code: public static function send($socket, $command, array $params = array())
      {
          if (!isset(self::$commands[$command])) {
              throw new Exception('Invalid command: ' . $command);
          }
  
          $data = array();
          foreach (self::$commands[$command][1] as $field) {
              if (isset($params[$field])) {
                  $data[] = $params[$field];
              }
          }
  
          $d = implode("\x00", $data);
  
          $cmd = "\0REQ" . pack(
              'NN',
              self::$commands[$command][0],
              self::stringLength($d)
          ) . $d;
  
          $cmdLength = self::stringLength($cmd);
          $written = 0;
          $error = false;
          do {
              $check = @socket_write($socket,
                                     self::subString($cmd, $written, $cmdLength),
                                     $cmdLength);
  
              if ($check === false) {
                  if (socket_last_error($socket) == SOCKET_EAGAIN or
                      socket_last_error($socket) == SOCKET_EWOULDBLOCK or
                      socket_last_error($socket) == SOCKET_EINPROGRESS) {
                      // skip this is okay
                  } else {
                      $error = true;
                      break;
                  }
              }
  
              $written += (int) $check;
          } while ($written < $cmdLength);
  
          if ($error === true) {
              $errno = socket_last_error($socket);
              $errstr = socket_strerror($errno);
              throw new Exception(
                  "Could not write command to socket ($errno: $errstr)"
              );
          }
      }
code_tokens: public static function send ( $ socket , $ command , array $ params = array ( ) ) { if ( ! isset ( self :: $ commands [ $ command ] ) ) { throw new Exception ( 'Invalid command: ' . $ command ) ; } $ data = array ( ) ; foreach ( self :: $ commands [ $ command ] [ 1 ] as $ field ) { if ( isset ( $ params [ $ field ] ) ) { $ data [ ] = $ params [ $ field ] ; } } $ d = implode ( "\x00" , $ data ) ; $ cmd = "\0REQ" . pack ( 'NN' , self :: $ commands [ $ command ] [ 0 ] , self :: stringLength ( $ d ) ) . $ d ; $ cmdLength = self :: stringLength ( $ cmd ) ; $ written = 0 ; $ error = false ; do { $ check = @ socket_write ( $ socket , self :: subString ( $ cmd , $ written , $ cmdLength ) , $ cmdLength ) ; if ( $ check === false ) { if ( socket_last_error ( $ socket ) == SOCKET_EAGAIN or socket_last_error ( $ socket ) == SOCKET_EWOULDBLOCK or socket_last_error ( $ socket ) == SOCKET_EINPROGRESS ) { // skip this is okay } else { $ error = true ; break ; } } $ written += ( int ) $ check ; } while ( $ written < $ cmdLength ) ; if ( $ error === true ) { $ errno = socket_last_error ( $ socket ) ; $ errstr = socket_strerror ( $ errno ) ; throw new Exception ( "Could not write command to socket ($errno: $errstr)" ) ; } }
docstring: Send a command to Gearman.
  
  This is the command that takes the string version of the command you
  wish to run (e.g. 'can_do', 'grab_job', etc.) along with an array of
  parameters (in key value pairings) and packs it all up to send across
  the socket.
  
  @param resource $socket  The socket to send the command to
  @param string   $command Command to send (e.g. 'can_do')
  @param array    $params  Params to send
  
  @see MHlavac\Gearman\Connection::$commands, MHlavac\Gearman\Connection::$socket
  
  @throws \MHlavac\Gearman\Exception on invalid command or unable to write
  
  @return bool
docstring_tokens: Send a command to Gearman .