[原创] PHP 兼容 Curl/Socket/Stream 的 HTTP 操作类
<?php
/************************************************************
* 描述:HTTP操作类
* 作者:heiyeluren
* 创建:2009/12/13 04:43
* 修改:2009/12/16 10:30 实现基本HTTP各种接口操作支持
*
************************************************************/
/**
* HTTP功能工厂方法类
*
* 调用示例代码:
try {
$http = Http::factory('http://www.baidu.com', Http::TYPE_SOCK );
echo $http->get();
$http = Http::factory('http://127.0.0.1/test/i.php', Http::TYPE_SOCK );
echo $http->post('', array('user'=>'我们', 'nick'=>'ASSADF@#!32812989+-239%ASDF'), '', array('aa'=>'bb', 'cc'=>'dd'));
} catch (Exception $e) {
echo $e->getMessage();
}
*/
class Http
{
/**
* @var 使用 CURL
*/
const TYPE_CURL = 1;
/**
* @var 使用 Socket
*/
const TYPE_SOCK = 2;
/**
* @var 使用 Stream
*/
const TYPE_STREAM = 3;
/**
* 保证对象不被clone
*/
private function __clone() {}
/**
* 构造函数
*/
private function __construct() {}
/**
* HTTP工厂操作方法
*
* @param string $url 需要访问的URL
* @param int $type 需要使用的HTTP类
* @return object
*/
public static function factory($url = '', $type = self::TYPE_SOCK){
if ($type == ''){
$type = self::TYPE_SOCK;
}
switch($type) {
case self::TYPE_CURL :
if (!function_exists('curl_init')){
throw new Exception(__CLASS__ . " PHP CURL extension not install");
}
$obj = Http_Curl::getInstance($url);
break;
case self::TYPE_SOCK :
if (!function_exists('fsockopen')){
throw new Exception(__CLASS__ . " PHP function fsockopen() not support");
}
$obj = Http_Sock::getInstance($url);
break;
case self::TYPE_STREAM :
if (!function_exists('stream_context_create')){
throw new Exception(__CLASS__ . " PHP Stream extension not install");
}
$obj = Http_Stream::getInstance($url);
break;
default:
throw new Exception("http acc
相关文档:
<?php
//新建目录
mkdir("/path/to/my/dir", 0700); //0700表示权限最大
//删除目录
rmdir("/path/to/my/dir");
//遍历目录
$p =dir(/etc/php5);
echo "handler:".$p->handler;
while(false!=$entry=$p->read()){
echo $entry."\n" ;
}
$p->close();
//输出文件内容
$handle=@ ......
2009-10-22 09:16
|
322次阅读
|
【已有0
条评论】发表评论
关键词:PHP
| 感谢yvonne_826
的提供
|
收藏这篇新闻
日前,PHP语言及工具供应商Zend
Technologies宣布将联手云计算应用管理领军企业RightScale,帮助PHP开发者进入云计算的应用。RightScale将 ......
HTTP Only cookies without PHP 5.2
by Matt Mecham
on September 12, 2006
For a while, Microsoft have had a flag
for cookies called ‘httponly’. This doesn’t sound particularly
exciting, but it is a vital step forward for web application security.
This flag tells Internet Expl ......
PHP]
;;;;;;;;;;;
; WARNING ;
;;;;;;;;;;;
; This is the default settings file for new PHPinstallations.
; By default, PHP installs itself with a configuration suitablefor
; development purposes, and *NOT* for production purposes.
; For several security-oriented considerations that should betak ......
PHP小实例-制作留言本
第一步:在mysql中新建数据库bbs 然后执行sql代码
CREATE TABLE `message` (
`id` tinyint(1) NOT NULL auto_increment,
`user` varchar(25) NOT NULL,
`title` varchar(50) NOT NULL,
`content` tinytext NOT NULL,
`lastdate` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT ......