athlon1600/php-proxy

v5.2.0 2019-12-31 20:33 UTC

This package is auto-updated.

Last update: 2024-09-04 03:44:38 UTC


README

php-proxy

基于PHP、Symfony和cURL构建的代理脚本。该库借鉴了Glype、Jenssegers代理和Guzzle的想法。

PHP-Proxy网络应用程序

如果你在寻找一个作为网络应用程序运行的脚本版本,类似于Glype,那么请访问php-proxy-app

查看此php-proxy的实际应用:proxy.unblockvideos.com

安装

使用Composer进行安装

composer require athlon1600/php-proxy

示例

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();

插件示例

namespace Proxy\Plugin;

use Proxy\Plugin\AbstractPlugin;
use Proxy\Event\ProxyEvent;

use Proxy\Html;

class MultiSiteMatchPlugin extends AbstractPlugin {

	// Matches multiple domain names (abc.com, abc.de, abc.pl) using regex (you MUST use / character)
	protected $url_pattern = '/^abc\.(com|de|pl)$/is';
	// Matches a single domain name
	//protected $url_pattern = 'abc.com';
	
	public function onCompleted(ProxyEvent $event){
	
		$response = $event['response'];
		
		$html = $response->getContent();
		
		// do your stuff here...
		
		$response->setContent($html);
	}
}

请注意,在$url_pattern上使用正则表达式时必须使用/字符