当前位置: 首页>>代码示例>>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;未经允许,请勿转载。