Download the PHP package snapsearch/snapsearch-client-php without Composer
On this page you can find all versions of the php package snapsearch/snapsearch-client-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download snapsearch/snapsearch-client-php
More information about snapsearch/snapsearch-client-php
Files in snapsearch/snapsearch-client-php
Package snapsearch-client-php
Short Description PHP HTTP Client Middleware Libraries for SnapSearch. Search engine optimisation for single page applications.
License MIT
Homepage https://github.com/SnapSearch/SnapSearch-Client-PHP
Informations about the package snapsearch-client-php
Snapsearch Client PHP
Snapsearch Client PHP is PHP based framework agnostic HTTP client library for SnapSearch (https://snapsearch.io/).
- It's PSR-0 compliant.
- Compatible with Stack PHP or HTTP Kernel frameworks.
- Works on HHVM. (Check Travis!)
Snapsearch is a search engine optimisation (SEO) and robot proxy for complex front-end javascript & AJAX enabled (potentially realtime) HTML5 web applications.
Search engines like Google's crawler and dumb HTTP clients such as Facebook's image extraction robot cannot execute complex javascript applications. Complex javascript applications include websites that utilise AngularJS, EmberJS, KnockoutJS, Dojo, Backbone.js, Ext.js, jQuery, JavascriptMVC, Meteor, SailsJS, Derby, RequireJS and much more. Basically any website that utilises javascript in order to bring in content and resources asynchronously after the page has been loaded, or utilises javascript to manipulate the page's content while the user is viewing them such as animation.
Snapsearch intercepts any requests made by search engines or robots and sends its own javascript enabled robot to extract your page's content and creates a cached snapshot. This snapshot is then passed through your own web application back to the search engine, robot or browser.
Snapsearch's robot is an automated load balanced Firefox browser. This Firefox browser is kept up to date with the nightly versions, so we'll always be able to serve the latest in HTML5 technology. Our load balancer ensures your requests won't be hampered by other user's requests.
For more details on how this works and the benefits of usage see https://snapsearch.io/
SnapSearch provides similar libraries in other languages: https://github.com/SnapSearch/Snapsearch-Clients
Installation
Requires 5.3.3 or above and Curl extension.
Composer
Add this to your composer.json
Then run composer install
or composer update
.
Native
Just extract repository into your library location. Then use your own PSR-0 autoloader to autoload the classes inside src/SnapSearchClientPHP/
.
You can also use the supplied autoloader. First clone this project to your desired location, then write:
If you don't want to use an autoloader, just require all the classes inside src/SnapSearchClientPHP/
except Bootstrap.php
.
Note you will have to install the dependencies and autoload them manually as well. Look into composer.json
file and find the dependencies in the "require"
section.
Don't forget about the resources/
folder containing the necessary resources for this library to work.
Usage
SnapSearchClientPHP should be best started at the entry point your application. This could be inside a front controller, bootstrapping process, IOC container, or middleware. For a single page application, your entry point would be the code that first presents the initial HTML page.
For full documentation on the API and API request parameters see: https://snapsearch.io/documentation
By the way, you need to blacklist non-html resources such as sitemap.xml
. This is explained in https://snapsearch.io/documentation#notes
Basic Usage
Here's an example $response
variable (not all variables are available, you need to check the request parameters):
Advanced Usage
Stack PHP Usage
Stack PHP is a HTTP Kernel Middleware Layer Framework for PHP similar to Ruby Rack or Node Connect. The below example uses PHP 5.4 code.
The $check_file_extensions
boolean for the Detector constructor is available for applications that might serve static files. Usually the HTTP server serves up static files and these requests never get proxied to the application, this is why by default this boolean is false. However in cases where it does serve up static files, you can switch this to true to prevent static files routes from being intercepted.
It can be more efficient or easier to blacklist routes which lead to static files instead. This has the advantage of allowing you to prevent routes that go to binary resources which may not end in specific file extensions. Such as streaming audio/video.
SnapSearchClientPHP can of course be used in other areas such as javascript enhanced scraping, so it doesn't force you to put it at the entry point if you're using it for other purposes. In that case just use the SnapSearchPHP\Client
to send requests to the SnapSearch API.
Proxies
SnapSearch-Client-PHP uses the Symfony HTTP Foundation Request Object as an abstraction of the HTTP request. This allows you considerable flexibility and constructing the HTTP request especially when you're behind a reverse proxy such as a load balancer. If you are behind a reverse proxy, certain information such as the request protocol is not where it is normally. You can configure the Symfony HTTP Foundation Request Object to handle these edge cases, and simply pass your instance into the Detector. See this for more information: http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html
Development
Install/update dependencies with composer:
Make your changes, synchronise, then create a new tag:
Packagist is integrated in the Github Service Hooks, it will automatically release the new package.
Tests
Unit tests are written using Codeception. Codeception has already been bootstrapped (codecept bootstrap
). To run tests use codecept run
or codecept run --debug
for debug messages. If you change the Codeception configuration files or add extra functions to the helpers make sure to run codecept build
so that the settings take effect.