资源说明:php-proxy 是基于 PHP,Symfony 和 cURL 的代理脚本,这个库借鉴了 Glype,Jenssegers proxy 和 Guzzle 的经验。示例require('vendor/autoload.php');
use Proxy\Http\Request;
use Proxy\Proxy;
$request = Request::createFromGlobals();
$proxy = new Proxy();
$proxy->getEventDispatcher()->addListener('request.before_send', function($event){
$event['request']->headers->set('X-Forwarded-For', 'php-proxy');
});
$proxy->getEventDispatcher()->addListener('request.sent', function($event){
if($event['response']->getStatusCode() != 200){
die("Bad status code!");
}
});
$proxy->getEventDispatcher()->addListener('request.complete', function($event){
$content = $event['response']->getContent();
$content .= '<!-- via php-proxy -->';
$event['response']->setContent($content);
});
$response = $proxy->forward($request, "http://www.yahoo.com");
// send the response back to the client
$response->send();
标签:phpproxy
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。