コード例 #1
0
 public function testDifferentInputTypes()
 {
     $history = new Pheanstalk_Socket_WriteHistory(1);
     foreach (array(null, false, 0, "", "0") as $input) {
         $this->assertEqual($history->log($input), $input);
         $this->assertTrue($history->isFullWithNoWrites());
     }
     foreach (array(true, 1, 2, "1", "2") as $input) {
         $this->assertEqual($history->log($input), $input);
         $this->assertFalse($history->isFullWithNoWrites());
     }
 }
コード例 #2
0
 public function write($data)
 {
     $history = new Pheanstalk_Socket_WriteHistory(self::WRITE_RETRIES);
     for ($written = 0, $fwrite = 0; $written < strlen($data); $written += $fwrite) {
         $fwrite = $this->_wrapper()->fwrite($this->_socket, substr($data, $written));
         $history->log($fwrite);
         if ($history->isFullWithNoWrites()) {
             throw new Pheanstalk_Exception_SocketException(sprintf('fwrite() failed to write data after %d tries', self::WRITE_RETRIES));
         }
     }
 }