本文整理汇总了PHP中stream_get_meta_data函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_get_meta_data函数的具体用法?PHP stream_get_meta_data怎么用?PHP stream_get_meta_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_get_meta_data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _recv
protected function _recv()
{
stream_set_timeout($this->_fp, 0, $this->_timeout_recv);
$data = fread($this->_fp, 24);
$info = stream_get_meta_data($this->_fp);
if ($info['timed_out']) {
return FALSE;
}
$array = $this->_show_request($data);
if ($array['bodylength']) {
$bodylength = $array['bodylength'];
$data = '';
while ($bodylength > 0) {
$recv_data = fread($this->_fp, $bodylength);
$bodylength -= strlen($recv_data);
$data .= $recv_data;
}
if ($array['extralength']) {
$extra_unpacked = unpack('Nint', substr($data, 0, $array['extralength']));
$array['extra'] = $extra_unpacked['int'];
}
$array['key'] = substr($data, $array['extralength'], $array['keylength']);
$array['body'] = substr($data, $array['extralength'] + $array['keylength']);
}
return $array;
}
开发者ID:aatty,项目名称:Heroku-Memcachier,代码行数:26,代码来源:Memcachesasl.php
示例2: send
/**
* @inheritdoc
*/
public function send($request)
{
$request->prepare();
$url = $request->getUrl();
$method = strtoupper($request->getMethod());
$contextOptions = ['http' => ['method' => $method, 'ignore_errors' => true], 'ssl' => ['verify_peer' => false]];
$content = $request->getContent();
if ($content !== null) {
$contextOptions['http']['content'] = $content;
}
$headers = $request->composeHeaderLines();
$contextOptions['http']['header'] = $headers;
$contextOptions = ArrayHelper::merge($contextOptions, $this->composeContextOptions($request->getOptions()));
$token = $request->client->createRequestLogToken($method, $url, $headers, $content);
Yii::info($token, __METHOD__);
Yii::beginProfile($token, __METHOD__);
try {
$context = stream_context_create($contextOptions);
$stream = fopen($url, 'rb', false, $context);
$responseContent = stream_get_contents($stream);
$metaData = stream_get_meta_data($stream);
fclose($stream);
} catch (\Exception $exception) {
Yii::endProfile($token, __METHOD__);
throw $exception;
}
Yii::endProfile($token, __METHOD__);
$responseHeaders = isset($metaData['wrapper_data']) ? $metaData['wrapper_data'] : [];
return $request->client->createResponse($responseContent, $responseHeaders);
}
开发者ID:hassiumsoft,项目名称:hasscms-app-vendor,代码行数:33,代码来源:StreamTransport.php
示例3: createFile
function createFile($imgURL)
{
$remImgURL = urldecode($imgURL);
$urlParced = pathinfo($remImgURL);
$remImgURLFilename = $urlParced['basename'];
$imgData = wp_remote_get($remImgURL);
if (is_wp_error($imgData)) {
$badOut['Error'] = print_r($imgData, true) . " - ERROR";
return $badOut;
}
$imgData = $imgData['body'];
$tmp = array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()] = tmpfile())));
if (!is_writable($tmp)) {
return "Your temporary folder or file (file - " . $tmp . ") is not witable. Can't upload images to Flickr";
}
rename($tmp, $tmp .= '.png');
register_shutdown_function(create_function('', "unlink('{$tmp}');"));
file_put_contents($tmp, $imgData);
if (!$tmp) {
return 'You must specify a path to a file';
}
if (!file_exists($tmp)) {
return 'File path specified does not exist';
}
if (!is_readable($tmp)) {
return 'File path specified is not readable';
}
// $data['name'] = basename($tmp);
return "@{$tmp}";
}
开发者ID:jguzmanf88,项目名称:social-networks-auto-poster-facebook-twitter-g,代码行数:30,代码来源:fp.api.php
示例4: analyze
public function analyze($handle)
{
$meta = stream_get_meta_data($handle);
if (file_exists($meta['uri'])) {
$type = 'file';
$source = $meta['uri'];
} else {
$type = 'buffer';
rewind($handle);
$source = fread($handle, 1000000);
}
$result = call_user_func("finfo_{$type}", $this->_resource, $source, FILEINFO_MIME);
if (strpos($result, 'application/ogg') === 0) {
$full = call_user_func("finfo_{$type}", $this->_resource, $source);
list($type, $attributes) = explode(';', $result, 2);
if (strpos($full, 'video') !== false) {
$type = 'video/ogg';
} elseif (strpos($full, 'audio') !== false) {
$type = 'audio/ogg';
}
return "{$type};{$attributes}";
}
if ($result != 'application/x-empty') {
return $result;
}
}
开发者ID:miznokruge,项目名称:base-cake,代码行数:26,代码来源:Fileinfo.php
示例5: testManualErrorOutputStream
public function testManualErrorOutputStream()
{
$adapter = new Stub(array('outputStream' => 'php://stderr'));
$this->assertTrue(is_resource($adapter->getOutputStream()));
$metaData = stream_get_meta_data($adapter->getOutputStream());
$this->assertEquals('php://stderr', $metaData['uri']);
}
开发者ID:bradley-holt,项目名称:zf2,代码行数:7,代码来源:ConsoleTest.php
示例6: setStream
/**
* Set the Stream resource we use to get the email text
* @return Object MimeMailParser Instance
* @param $stream Resource
*/
public function setStream($stream)
{
// streams have to be cached to file first
$meta = @stream_get_meta_data($stream);
if (!$meta || $meta['eof']) {
throw new \Exception('setStream() expects parameter stream to be readable stream resource.');
}
$tmp_fp = tmpfile();
if ($tmp_fp) {
while (!feof($stream)) {
fwrite($tmp_fp, fread($stream, 2028));
}
fseek($tmp_fp, 0);
$this->stream =& $tmp_fp;
} else {
throw new \Exception('Could not create temporary files for attachments. Your tmp directory may be unwritable by PHP.');
}
fclose($stream);
$this->resource = mailparse_msg_create();
// parses the message incrementally (low memory usage but slower)
while (!feof($this->stream)) {
mailparse_msg_parse($this->resource, fread($this->stream, 2082));
}
$this->parse();
return $this;
}
开发者ID:rgooding,项目名称:php-mime-mail-parser,代码行数:31,代码来源:Parser.php
示例7: _test_environment_getHello
function _test_environment_getHello($url)
{
$fp = fopen($url, 'r', false, stream_context_create(array('http' => array('method' => "GET", 'timeout' => '10', 'header' => "Accept-Encoding: deflate, gzip\r\n"))));
$meta = stream_get_meta_data($fp);
$encoding = '';
$length = 0;
foreach ($meta['wrapper_data'] as $i => $header) {
if (preg_match('@^Content-Length:\\s*(\\d+)$@i', $header, $m)) {
$length = $m[1];
} elseif (preg_match('@^Content-Encoding:\\s*(\\S+)$@i', $header, $m)) {
if ($m[1] !== 'identity') {
$encoding = $m[1];
}
}
}
$streamContents = stream_get_contents($fp);
fclose($fp);
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
if ($length != 6) {
echo "\nReturned content should be 6 bytes and not HTTP encoded.\n" . "Headers returned by: {$url}\n\n";
var_export($meta['wrapper_data']);
echo "\n\n";
}
}
return array('length' => $length, 'encoding' => $encoding, 'bytes' => $streamContents);
}
开发者ID:Bhaavya,项目名称:OpenLorenz,代码行数:26,代码来源:test_environment.php
示例8: formatMetadata
/**
* Format resource metadata.
*
* @param resource $value
*
* @return string
*/
protected function formatMetadata($value)
{
$props = array();
switch (get_resource_type($value)) {
case 'stream':
$props = stream_get_meta_data($value);
break;
case 'curl':
$props = curl_getinfo($value);
break;
case 'xml':
$props = array('current_byte_index' => xml_get_current_byte_index($value), 'current_column_number' => xml_get_current_column_number($value), 'current_line_number' => xml_get_current_line_number($value), 'error_code' => xml_get_error_code($value));
break;
}
if (empty($props)) {
return '{}';
}
$formatted = array();
foreach ($props as $name => $value) {
$formatted[] = sprintf('%s: %s', $name, $this->indentValue($this->presentSubValue($value)));
}
$template = sprintf('{%s%s%%s%s}', PHP_EOL, self::INDENT, PHP_EOL);
$glue = sprintf(',%s%s', PHP_EOL, self::INDENT);
return sprintf($template, implode($glue, $formatted));
}
开发者ID:GeorgeShazkho,项目名称:micros-de-conce,代码行数:32,代码来源:ResourcePresenter.php
示例9: stream_open
public function stream_open($path, $mode, $options, &$opened_path)
{
if (!self::$rootView) {
self::$rootView = new OC_FilesystemView('');
}
$path = str_replace('crypt://', '', $path);
if (dirname($path) == 'streams' and isset(self::$sourceStreams[basename($path)])) {
$this->source = self::$sourceStreams[basename($path)]['stream'];
$this->path = self::$sourceStreams[basename($path)]['path'];
$this->size = self::$sourceStreams[basename($path)]['size'];
} else {
$this->path = $path;
if ($mode == 'w' or $mode == 'w+' or $mode == 'wb' or $mode == 'wb+') {
$this->size = 0;
} else {
$this->size = self::$rootView->filesize($path, $mode);
}
OC_FileProxy::$enabled = false;
//disable fileproxies so we can open the source file
$this->source = self::$rootView->fopen($path, $mode);
OC_FileProxy::$enabled = true;
if (!is_resource($this->source)) {
OCP\Util::writeLog('files_encryption', 'failed to open ' . $path, OCP\Util::ERROR);
}
}
if (is_resource($this->source)) {
$this->meta = stream_get_meta_data($this->source);
}
return is_resource($this->source);
}
开发者ID:noci2012,项目名称:owncloud,代码行数:30,代码来源:cryptstream.php
示例10: _fetch
/**
*
* Support method to make the request, then return headers and content.
*
* @param string $uri The URI get a response from.
*
* @param array $headers A sequential array of header lines for the request.
*
* @param string $content A string of content for the request.
*
* @return array A sequential array where element 0 is a sequential array of
* header lines, and element 1 is the body content.
*
*/
protected function _fetch($uri, $headers, $content)
{
// prepare the stream context
$context = $this->_prepareContext($headers, $content);
// connect to the uri (suppress errors and deal with them later)
$stream = @fopen($uri, 'r', false, $context);
// did we hit any errors?
if ($stream === false) {
// the $http_response_header variable is automatically created
// by the streams extension
if (!empty($http_response_header)) {
// server responded, but there's no content
return array($http_response_header, null);
} else {
// no server response, must be some other error
throw $this->_exception('ERR_CONNECTION_FAILED', error_get_last());
}
}
// get the response message
$content = stream_get_contents($stream);
$meta = stream_get_meta_data($stream);
fclose($stream);
// did it time out?
if ($meta['timed_out']) {
throw $this->_exception('ERR_CONNECTION_TIMEOUT', array('uri' => $uri, 'meta' => $meta, 'content' => $content));
}
// return headers and content
return array($meta['wrapper_data'], $content);
}
开发者ID:btweedy,项目名称:foresmo,代码行数:43,代码来源:Stream.php
示例11: SendMsg2Daemon
function SendMsg2Daemon($ip, $port, $msg, $timeout = 15)
{
if (!$ip || !$port || !$msg) {
return array(false);
}
$errno;
$errstr;
$fp = @fsockopen($ip, $port, $errno, $errstr, $timeout);
if (!$fp) {
return array(false);
}
stream_set_blocking($fp, true);
stream_set_timeout($fp, $timeout);
@fwrite($fp, $msg . "\n");
$status = stream_get_meta_data($fp);
$ret;
if (!$status['timed_out']) {
$datas = 'data:';
while (!feof($fp)) {
$data = fread($fp, 4096);
if ($data) {
$datas = $datas . $data;
}
}
return array(true, $datas);
} else {
$ret = array(false);
}
@fclose($fp);
return ret;
}
开发者ID:ifzz,项目名称:distri.lua,代码行数:31,代码来源:control_action.php
示例12: getMetaData
/**
* Gets the metadata from a file url
*
* @param string %url to grab from
* @param int $redirect whether to redirect or not
* @return mixed stream data
* @throws Exception if file doesn't exist.
**/
public static function getMetaData($url, $redirect = 1)
{
$context = stream_context_create(array("http" => array("follow_location" => $redirect, "ignore_errors" => true, "method" => "HEAD")));
//"@" suppresses warnings and errors
$fd = @fopen($url, "rb", false, $context);
//grab the stream data
$streamData = stream_get_meta_data($fd);
fclose($fd);
$wrapperData = $streamData["wrapper_data"];
//loop through and find the "HTTP" attribute
$http = "";
foreach ($wrapperData as $data) {
if (strpos($data, "HTTP") !== false) {
$http = $data;
break;
}
}
if (strpos($http, "400")) {
throw new Exception("Bad request");
}
if (strpos($http, "401")) {
throw new Exception("Unauthorized");
}
if (strpos($http, "403")) {
throw new Exception("Forbidden");
}
if (strpos($http, "404")) {
throw new Exception("Not Found");
}
if (strpos($http, "418")) {
throw new Exception("Get your tea set");
}
return $streamData;
}
开发者ID:jmsaul,项目名称:open-trails,代码行数:42,代码来源:data-downloader.php
示例13: _sendHttpOpenSsl
function _sendHttpOpenSsl($msg, $server, $port, $timeout = 0, $username = '', $password = '')
{
if (!empty($timeout)) {
// Set timeout
$old_timeout = ini_get('default_socket_timeout');
ini_set('default_socket_timeout', $timeout);
}
$this->_sendHttpGenerate($msg, $username, $password);
$context = stream_context_create(array('http' => array('method' => 'POST', 'header' => preg_replace('/^.*?\\r\\n/', '', $this->headers), 'content' => $msg->payload), 'ssl' => array('verify_peer' => $this->verifyPeer, 'cafile' => $this->caFile)));
$protocol = $this->protocol == 'ssl://' ? 'https://' : 'http://';
$fp = @fopen("{$protocol}{$this->server}:{$port}{$this->path}", 'rb', false, $context);
if (!empty($timeout)) {
// Restore timeout
ini_set('default_socket_timeout', $old_timeout);
}
if (!$fp) {
$this->raiseError('Connection to RPC server ' . $server . ':' . $port . ' failed. ' . $this->errstr, XML_RPC_ERROR_CONNECTION_FAILED);
return 0;
}
$resp = $msg->parseResponseFile($fp);
$meta = stream_get_meta_data($fp);
if ($meta['timed_out']) {
fclose($fp);
$this->errstr = 'RPC server did not send response before timeout.';
$this->raiseError($this->errstr, XML_RPC_ERROR_CONNECTION_FAILED);
return 0;
}
fclose($fp);
return $resp;
}
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:30,代码来源:XmlRpcClient.php
示例14: request
/**
* Makes an HTTP request to put.io's API and returns the response.
* Relies on native PHP functions.
*
* NOTE!! Due to restrictions, files must be loaded into the memory when
* uploading. I don't recommend uploading large files using native
* functions. Only use this if you absolutely must! Otherwise, the cURL
* engine is much better!
*
* Downloading is no issue as long as you're saving the file somewhere on
* the file system rather than the memory. Set $outFile and you're all set!
*
* Returns false if a file was not found.
*
* @param string $method HTTP request method. Only POST and GET are
* supported.
* @param string $url Remote path to API module.
* @param array $params Variables to be sent.
* @param string $outFile If $outFile is set, the response will be
* written to this file instead of StdOut.
* @param bool $returnBool
* @param string $arrayKey Will return all data on a specific array key
* of the response.
* @param bool $verifyPeer If true, will use proper SSL peer/host
* verification.
* @return mixed
* @throws \PutIO\Exceptions\LocalStorageException
* @throws \PutIO\Exceptions\RemoteConnectionException
*/
public function request($method, $url, array $params = [], $outFile = '', $returnBool = \false, $arrayKey = '', $verifyPeer = \true)
{
list($url, $contextOptions) = $this->configureRequestOptions($url, $method, $params, $verifyPeer);
$fp = @fopen($url, 'rb', \false, stream_context_create($contextOptions));
$headers = stream_get_meta_data($fp)['wrapper_data'];
return $this->handleRequest($fp, $headers, $outFile, $returnBool, $arrayKey);
}
开发者ID:nicoSWD,项目名称:put.io-api-v2,代码行数:36,代码来源:NativeEngine.php
示例15: kill_client
function kill_client($port, $remipp)
{
global $g;
//$tcpsrv = "tcp://127.0.0.1:{$port}";
$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
$errval;
$errstr;
/* open a tcp connection to the management port of each server */
$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
$killed = -1;
if ($fp) {
stream_set_timeout($fp, 1);
fputs($fp, "kill {$remipp}\n");
while (!feof($fp)) {
$line = fgets($fp, 1024);
$info = stream_get_meta_data($fp);
if ($info['timed_out']) {
break;
}
/* parse header list line */
if (strpos($line, "INFO:") !== false) {
continue;
}
if (strpos($line, "SUCCESS") !== false) {
$killed = 0;
}
break;
}
fclose($fp);
}
return $killed;
}
开发者ID:mtisza,项目名称:pfsense,代码行数:32,代码来源:openvpn.widget.php
示例16: __construct
/**
* Initialize a new stream listener
*/
public function __construct($stream)
{
$this->stream = $stream;
stream_set_blocking($this->stream, 0);
$meta = stream_get_meta_data($this->stream);
if (substr($meta['mode'], -1) === '+') {
$this->writable = true;
$this->readable = true;
} else {
if (strpos($meta['mode'], 'r') !== false) {
$this->readable = true;
}
if (strpos($meta['mode'], 'w') !== false) {
$this->writable = true;
}
}
if ($this->readable) {
$this->ev_read = event_new();
event_set($this->ev_read, $this->stream, EV_READ | EV_PERSIST, array($this, '_read'));
Loop::attachEvent($this->ev_read);
}
if ($this->writable) {
$this->ev_write = event_new();
event_set($this->ev_write, $this->stream, EV_WRITE | EV_PERSIST, array($this, '_write'));
Loop::attachEvent($this->ev_write);
}
}
开发者ID:expressif,项目名称:stream,代码行数:30,代码来源:Event.php
示例17: load
public function load($var, $level = 1)
{
if (!$this->isResource($var)) {
throw new InvalidVariableTypeException();
}
$this->level = $level;
$this->resourceType = get_resource_type($var);
$this->resourceId = (int) $var;
if ($this->resourceType == 'stream') {
$stream_vars = stream_get_meta_data($var);
// prevent unix sistems getting stream in files
if (isset($stream_vars['stream_type']) && $stream_vars['stream_type'] == 'STDIO') {
$this->resourceType = 'file';
}
}
$this->variableWrapper = new VariableWrapper($this->getResourceType(), $var, VariableWrapper::TYPE_RESOURCE);
// metadata
if ($this->metadataResolver->has($this->variableWrapper)) {
$metadata = $this->metadataResolver->get($this->variableWrapper);
if (array_key_exists('help_link', $metadata)) {
$this->helpLink = $metadata['help_link'];
}
if (array_key_exists('icon', $metadata)) {
$this->icon = $metadata['icon'];
}
if (array_key_exists('version', $metadata)) {
$this->version = $metadata['version'];
}
}
// Resource data
$this->loadData($var);
}
开发者ID:jaime8111,项目名称:precio-electricidad,代码行数:32,代码来源:ResourceType.php
示例18: request
/**
* Execute a HTTP request.
*
* @param string $url
* @param array $options
*
* @return mixed
*/
public function request($url, $options = array())
{
// parse request
$request = $this->parseRequest($url, $options);
// create stream options
$options = array('http' => array('method' => $request['method'], 'protocol_version' => $request['version'], 'max_redirects' => $request['redirects'], 'timeout' => $request['timeout'], 'ignore_errors' => true, 'content' => $request['body']));
// create header string
$options['http']['header'] = $this->buildHeader($request['header']);
if (!empty($request['cookies'])) {
$options['http']['header'] .= $this->buildCookies($request['cookies']);
}
// connect with fopen and streams
$res = false;
$fp = @fopen($url, 'r', false, stream_context_create($options));
$res = stream_get_contents($fp);
$meta = stream_get_meta_data($fp);
fclose($fp);
// parse response
$res = $this->parseResponse((isset($meta['wrapper_data']) ? implode($this->line_break, $meta['wrapper_data']) . $this->line_break . $this->line_break : null) . $res);
// save to file
if ($res && $request['file'] && file_put_contents($request['file'], $res['body']) === false) {
return false;
}
return $res;
}
开发者ID:NavaINT1876,项目名称:ccustoms,代码行数:33,代码来源:StreamTransport.php
示例19: fromFile_exceed_buffer
/**
* @test
*/
public function fromFile_exceed_buffer()
{
//Create a 10k temp file
$temp = tmpfile();
fwrite($temp, str_repeat("1", 10000));
$meta_data = stream_get_meta_data($temp);
$filename = $meta_data["uri"];
/** @var LoopInterface $loop */
$loop = \EventLoop\getLoop();
$source = new FromFileObservable($filename);
$result = false;
$complete = false;
$error = false;
$source->subscribe(new CallbackObserver(function ($value) use(&$result) {
$result = $value;
}, function ($e) use(&$error) {
$error = true;
}, function () use(&$complete) {
$complete = true;
}));
$loop->tick();
$this->assertEquals("4096", strlen($result));
$this->assertFalse($complete);
$this->assertFalse($error);
$loop->tick();
$this->assertEquals("4096", strlen($result));
$this->assertFalse($complete);
$this->assertFalse($error);
$loop->tick();
$this->assertEquals("1808", strlen($result));
$this->assertTrue($complete);
$this->assertFalse($error);
}
开发者ID:RxPHP,项目名称:RxStream,代码行数:36,代码来源:FromFileObservableTest.php
示例20: __construct
/**
* Create a new outputter.
*
* \param resource $stream
* The PHP stream this outputter
* will write to.
*/
public function __construct($stream)
{
if (@stream_get_meta_data($stream) === null) {
throw new \InvalidArgumentException('Not a valid stream');
}
$this->stream = $stream;
}
开发者ID:fpoirotte,项目名称:xrl,代码行数:14,代码来源:Output.php
注:本文中的stream_get_meta_data函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论