zeichen32 / website-info
PHP 库,用于从任何网页中检索服务器信息,如安装的 CMS、Web 服务器等
v1.0.2
2015-01-22 22:43 UTC
Requires
- php: >=5.4.0
- embed/embed: >=1.8.3 <1.9
- saxulum/saxulum-http-client-adapter-guzzle: ~1.0
- saxulum/saxulum-http-client-interface: ~1.0
- symfony/dom-crawler: 2.6.*
- symfony/event-dispatcher: 2.6.*
- twodevs/cache-interface: ~1.0
- webignition/url: ~1.9
Requires (Dev)
- desarrolla2/cache: ~1.8
- doctrine/cache: ~1.4
- illuminate/cache: ~4.2
- phpunit/phpunit: 4.4.*
- zendframework/zend-cache: ~2.3
Suggests
- doctrine/cache: Allows to cache the response container
- zendframework/zend-cache: Allows to cache the response container
This package is auto-updated.
Last update: 2024-08-29 04:13:04 UTC
README
PHP 库,用于从任何网页中检索服务器信息,如安装的 CMS、Web 服务器、DNS 查询等...
要求
- PHP 5.4+
- 已安装 Curl 库
- allow_url_fopen: 开启
安装库
安装此库的首选方式是使用Composer。
$ php composer.phar require zeichen32/website-info ~1.0
用法
// Create a new WebsiteInfo instance with all default parser $ws = \WebsiteInfo\Factory::createWithDefaultParser(); // OR $ws = \WebsiteInfo\Factory::create(array( new \WebsiteInfo\Parser\Webserver\Apache(), new \WebsiteInfo\Parser\Webserver\Nginx(), new \WebsiteInfo\Parser\Webserver\IIS(), // ... )); // Retrieve informations about wordpress.com $result = $ws->get('http://wordpress.com'); print_r($result);
Array ( [headers] => Array ( [request] => Array ( [Host] => Array ( [0] => wordpress.org ) [user-agent] => Array ( [0] => WebsiteInfo ) ) [response] => Array ( [Server] => Array ( [0] => nginx ) [Content-Type] => Array ( [0] => text/html; charset=utf-8 ) ) ) [webserver] => Array ( [name] => Nginx [version] => unknown [score] => 1 [raw] => nginx ) [embed] => Array ( [title] => WordPress Blog Tool, Publishing Platform, and CMS [description] => [url] => https://wordpresstheme.cn/ [type] => link [embed_code] => [images] => Array ( [collection] => Array ( [0] => http://wpdotorg.files.wordpress.com/2012/10/red-negative-w-crop.jpg ) [base] => Array ( [image] => http://wpdotorg.files.wordpress.com/2012/10/red-negative-w-crop.jpg [width] => 264 [height] => 354 [aspect_ration] => ) ) [author] => Array ( [name] => [url] => ) [provider] => Array ( [name] => wordpress [url] => https://wordpresstheme.cn [icon] => https://s.w.org/favicon.ico?2 [icons] => Array ( [0] => https://wordpresstheme.cn/favicon.ico [1] => https://wordpresstheme.cn/favicon.png ) ) ) [lookup] => Array ( [ip] => Array ( [0] => 66.155.40.249 [1] => 66.155.40.250 ) [hostname] => wordpress.org [dns] => Array ( ... ) ) )
可用的解析器
创建自己的解析器
- 创建一个新解析器,用于对响应进行某些操作
namespace Acme\Parser; use WebsiteInfo\Event\ParseResponseEvent; use WebsiteInfo\Parser\AbstractParser; class MyParser extends AbstractParser { public function onParseResponse(ParseResponseEvent $event) { // Get response object $response = $event->getResponse(); // Do something with the response $something = $this->doSomething( (string) $response->getBody() ); // Add a new section to the output container $event->getData()->addSection('my_new_section', array( 'foo' => 'bar', 'version' => '1.0', 'score' => 1, 'raw' => $something )); } }
- 使用您的解析器
// Create a new WebsiteInfo instance $ws = \WebsiteInfo\Factory::createWithDefaultParser(); // Register your parser $ws->addParser(new \Acme\Parser\MyParser()); // Retrieve informations about wordpress.com $result = $ws->get('http://wordpress.com');
使用结果容器缓存
- 使用 ArrayCache(内存缓存)
// Create a new WebsiteInfo instance $ws = \WebsiteInfo\Factory::createWithDefaultParser(); // Using the array cache $ws->setCache(new \TwoDevs\Cache\ArrayCache()); // Retrieve informations about wordpress.com $result = $ws->get('http://wordpress.com');
- 如果已安装 doctrine 缓存,可以使用 doctrine 缓存适配器来缓存结果容器。
// Create a new WebsiteInfo instance $ws = \WebsiteInfo\Factory::createWithDefaultParser(); // Create a new DoctrineCache instance $doctrineCache = new \Doctrine\Common\Cache\FilesystemCache('var/cache'); // Create a new DoctrineCache adapter $cacheAdapter = new \TwoDevs\Cache\DoctrineCache($doctrineCache); // Using the cache $ws->setCache($cacheAdapter); // Retrieve informations about wordpress.com $result = $ws->get('http://wordpress.com');
- 如果已安装 zend 缓存,可以使用 zend 缓存适配器来缓存结果容器。
// Create a new WebsiteInfo instance $ws = \WebsiteInfo\Factory::createWithDefaultParser(); // Create a new ZendStorage instance $zendCache = new \Zend\Cache\Storage\Adapter\Memory(); // Create a new ZendCache adapter $cacheAdapter = new \TwoDevs\Cache\ZendCache($zendCache); // Using the cache $ws->setCache($cacheAdapter); // Retrieve informations about wordpress.com $result = $ws->get('http://wordpress.com');
如何使用不同的 HttpClient
此库使用Saxulum HttpClientInterface,允许您简单地更改所使用的 HttpClient。
例如,您想使用Buzz作为 HttpClient
- 将 Buzz 适配器添加到您的 composer.json
$ php composer.phar require saxulum-http-client-adapter-buzz ~1.0
- 创建新的 BuzzClient
// Create a new Buzz Client $buzz = new \Buzz\Browser(); // Create the client adapter $client = new \Saxulum\HttpClient\Buzz\HttpClient($guzzle); // Create a new WebsiteInfo instance with all default parser and custom client $ws = \WebsiteInfo\Factory::createWithDefaultParser($client); // Retrieve informations about wordpress.com $result = $ws->get('http://wordpress.com'); print_r($result);