`
carge
  • 浏览: 50138 次
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

PHP学习

 
阅读更多

 

 

1、PHP中的输入输出流

 

php://stdin,php://stdout 和 php://stderr 允许访问 PHP 进程相应的输入或者输出流。

 

php://output 允许向输出缓冲机制写入数据,和 print() 与 echo() 的方式相同。

 

php://input 允许您读取 POST 的原始数据。 和 $HTTP_RAW_POST_DATA 比起来,它给内存带来的压力较小,并且不需要任何特殊的 php.ini 设置。 例如:当HTTP Request 的contentType为text/XML时,可以用以下方式来读取完整的XML文档内容。

 

发送请求:

<?php
// create a new curl resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://localhost/go/test2.php");
curl_setopt($ch, CURLOPT_PORT, "80");

//不把响应的头信息显示出来
curl_setopt($ch, CURLOPT_HEADER, 0);
$xml = file_get_contents('post.xml');
//发送头信息
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml",'Content-length: '. strlen($xml))); 

//请求方式为POST
curl_setopt($ch, CURLOPT_POST, 1);


//设置完整的POST body
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);

// grab URL and pass it to the browser
curl_exec($ch);

// close curl resource, and free up system resources
curl_close($ch);
?> 

 

test2.php中输出请求的XML文档:

 

file_get_contents("php://input");

 

php://stdin 和 php://input 是只读的,同时,php://stdout,php://stderr 和 php://output 是只写的。

 

php://filter 是一种设计用来允许过滤器程序在打开时成为流的封装协议。这对于单独具有完整功能的文件函数例如 readfile(),file() 和 file_get_contents() 很有用,否则就没有机会在读取内容之前将过滤器应用于流之上。

php://filter 的目标接受随后的'参数'作为其'路径'的一部分。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics