當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Stream::write方法代碼示例

本文整理匯總了PHP中Stream::write方法的典型用法代碼示例。如果您正苦於以下問題:PHP Stream::write方法的具體用法?PHP Stream::write怎麽用?PHP Stream::write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Stream的用法示例。


在下文中一共展示了Stream::write方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: archiveBytesAsStream

 /**
  * Returns 
  *
  * @return  io.Stream
  */
 protected function archiveBytesAsStream($version = -1)
 {
     static $bytes = array(1 => "CCA", 2 => "CCA");
     $s = new Stream();
     $s->open(STREAM_WRITE);
     $s->write($bytes[$version < 0 ? $this->version() : $version]);
     $s->write(str_repeat("", 248));
     // Reserved bytes
     $s->close();
     return $s;
 }
開發者ID:Gamepay,項目名稱:xp-framework,代碼行數:16,代碼來源:ArchiveTest.class.php

示例2: write

 public function write($string)
 {
     parent::write($string);
     $result = fwrite($this->stream, $string);
     if ($result === false) {
         throw new \Exception('Unable to write stream');
     }
     return $result;
 }
開發者ID:locphp,項目名稱:rsf,代碼行數:9,代碼來源:ResourceStream.php

示例3: get_contents

 public function get_contents()
 {
     $data = 'Test';
     $f = new Stream();
     $f->open(STREAM_MODE_WRITE);
     $f->write($data);
     $f->close();
     $this->assertEquals($data, FileUtil::getContents($f));
 }
開發者ID:Gamepay,項目名稱:xp-framework,代碼行數:9,代碼來源:FileUtilTest.class.php

示例4: parseSizeForJPEG

 /**
  * @return array|bool
  */
 protected function parseSizeForJPEG()
 {
     $state = null;
     while (true) {
         switch ($state) {
             default:
                 $this->stream->read(2);
                 $state = 'started';
                 break;
             case 'started':
                 $b = $this->getByte();
                 if ($b === false) {
                     return false;
                 }
                 $state = $b == 0xff ? 'sof' : 'started';
                 break;
             case 'sof':
                 $b = $this->getByte();
                 if ($b === 0xe1) {
                     $data = $this->stream->read($this->readInt($this->stream->read(2)) - 2);
                     $stream = new Stream();
                     $stream->write($data);
                     if ($stream->read(4) === 'Exif') {
                         $stream->read(2);
                         $exif = new Faster_Image_B52f1a8_Exif_Parser($stream);
                     }
                     break;
                 }
                 if (in_array($b, range(0xe0, 0xef))) {
                     $state = 'skipframe';
                     break;
                 }
                 if (in_array($b, array_merge(range(0xc0, 0xc3), range(0xc5, 0xc7), range(0xc9, 0xcb), range(0xcd, 0xcf)))) {
                     $state = 'readsize';
                     break;
                 }
                 if ($b == 0xff) {
                     $state = 'sof';
                     break;
                 }
                 $state = 'skipframe';
                 break;
             case 'skipframe':
                 $skip = $this->readInt($this->stream->read(2)) - 2;
                 $this->stream->read($skip);
                 $state = 'started';
                 break;
             case 'readsize':
                 $c = $this->stream->read(7);
                 $size = array($this->readInt(substr($c, 5, 2)), $this->readInt(substr($c, 3, 2)));
                 if (isset($exif) && $exif->isRotated()) {
                     return array_reverse($size);
                 }
                 return $size;
         }
     }
     return false;
 }
開發者ID:Automattic,項目名稱:amp-wp,代碼行數:61,代碼來源:class-faster-image-b52f1a8-image-parser.php

示例5: save

 /**
  * Write the stream to the given destionation directly without using extra memory like storing in an array etc.
  *
  * @param mixed $destination file path.
  */
 public function save($destination)
 {
     $dest = new Stream(is_resource($destination) ? $destination : fopen($destination, 'w+'));
     while (!$this->feof()) {
         $dest->write($this->read());
     }
     if (!is_resource($destination)) {
         // close the file if we opened it otwhise dont touch.
         $dest->close();
     }
 }
開發者ID:RituKapoor,項目名稱:php-apk-parser,代碼行數:16,代碼來源:Stream.php

示例6: getThumbnail

 /**
  * Get Thumbnail
  *
  * @return  img.Image  
  */
 public function getThumbnail()
 {
     $s = new Stream();
     $s->open(STREAM_MODE_WRITE);
     $s->write(exif_thumbnail($this->getFilename()));
     $s->rewind();
     return Image::loadFrom(new StreamReader($s));
 }
開發者ID:Gamepay,項目名稱:xp-framework,代碼行數:13,代碼來源:ExifData.class.php

示例7: syncFromAof

 /**
  * @param $file
  * @param $dstRedisServer
  * @param int $seek
  * @return bool
  */
 static function syncFromAof($file, $dstRedisServer, $seek = 0)
 {
     $fp = fopen($file, 'r');
     if (!$fp) {
         return false;
     }
     //偏移
     if ($seek > 0) {
         fseek($fp, $seek);
     }
     //目標Redis服務器
     $dstRedis = stream_socket_client($dstRedisServer, $errno, $errstr, 10);
     if (!$dstRedis) {
         return false;
     }
     $n_bytes = $seek;
     $n_lines = 0;
     $n_success = 0;
     $_send = '';
     $patten = "#^\\*(\\d+)\r\n\$#";
     readfile:
     while (!feof($fp)) {
         $line = fgets($fp, 8192);
         if ($line === false) {
             echo "line empty\n";
             break;
         }
         $n_lines++;
         $r = preg_match($patten, $line);
         if ($r) {
             if ($_send) {
                 if (Stream::write($dstRedis, $_send) === false) {
                     die("寫入Redis失敗. {$_send}");
                 }
                 $n_bytes += strlen($_send);
                 //清理數據
                 if (fread($dstRedis, 8192) == false) {
                     echo "讀取Redis失敗. {$_send}\n";
                     for ($i = 0; $i < 10; $i++) {
                         $dstRedis = stream_socket_client($dstRedisServer, $errno, $errstr, 10);
                         if (!$dstRedis) {
                             echo "連接到Redis({$dstRedisServer})失敗, 1秒後重試.\n";
                             sleep(1);
                         }
                     }
                     if (!$dstRedis) {
                         echo "連接到Redis({$dstRedisServer})失敗\n";
                         return false;
                     }
                     $_send = $line;
                     continue;
                 }
                 $n_success++;
                 if ($n_success % 10000 == 0) {
                     $seek = ftell($fp);
                     echo "KEY: {$n_success}, LINE: {$n_lines}, BYTE: {$n_bytes}, SEEK: {$seek}. 完成\n";
                 }
             }
             $_send = $line;
         } else {
             $_send .= $line;
         }
     }
     wait:
     //等待100ms後繼續讀
     sleep(2);
     $seek = ftell($fp);
     echo "read eof, seek={$seek}\n";
     //關閉文件
     fclose($fp);
     $fp = fopen($file, 'r');
     if (!$fp) {
         exit("打開文件失敗,seek={$seek}\n");
     }
     if (fseek($fp, $seek) < 0) {
         exit("feek({$seek})失敗\n");
     }
     goto readfile;
 }
開發者ID:out001a,項目名稱:framework,代碼行數:85,代碼來源:Redis.php

示例8: testCannotRetrieveStreamAfterMove

 public function testCannotRetrieveStreamAfterMove()
 {
     $this->setExpectedException("RuntimeException", "File has already been moved");
     $stream = new Stream("php://temp", "wb+");
     $stream->write("test");
     $upload = new UploadedFile($stream, 1, UPLOAD_ERR_OK);
     $upload->moveTo(__DIR__ . "/tmpfile");
     $this->assertTrue(file_exists(__DIR__ . "/tmpfile"));
     $upload->getStream();
 }
開發者ID:fabyscore,項目名稱:fabyscore-lib,代碼行數:10,代碼來源:UploadedFileTest.php

示例9: write

 public function write($content)
 {
     $modified = $this->mutateOut($content);
     return parent::write($modified);
 }
開發者ID:MrYogi,項目名稱:hasoffers-promotional-platform,代碼行數:5,代碼來源:Filter.php

示例10: positionAfterReOpen

 public function positionAfterReOpen()
 {
     $s = new Stream();
     $s->open(STREAM_MODE_WRITE);
     $s->write('GIF89a');
     $s->close();
     $s->open(STREAM_MODE_READ);
     $this->assertEquals(0, $s->tell());
     $this->assertEquals('GIF89a', $s->read());
     $s->close();
 }
開發者ID:Gamepay,項目名稱:xp-framework,代碼行數:11,代碼來源:StreamTest.class.php


注:本文中的Stream::write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。