PHPackages                             franzip/serp-fetcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. franzip/serp-fetcher

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

franzip/serp-fetcher
====================

Wrapper around SimpleHtmlDom to easily fetch data from Search Engine Result Pages with built-in caching support.

11431PHP

Since Oct 7Pushed 10y ago1 watchersCompare

[ Source](https://github.com/franzip/serp-fetcher)[ Packagist](https://packagist.org/packages/franzip/serp-fetcher)[ RSS](/packages/franzip-serp-fetcher/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/e384af8c761e1ddeb0716e28671140a266f96415eb432cd1b5a9c033a7bca8e2/68747470733a2f2f7472617669732d63692e6f72672f6672616e7a69702f736572702d666574636865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/franzip/serp-fetcher)[![Coverage Status](https://camo.githubusercontent.com/54fdf85fe4359bbb18b7523287176b5e9a7bd7d7f24b9be31fd180af3b59f013/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6672616e7a69702f736572702d666574636865722f62616467652e737667)](https://coveralls.io/r/franzip/serp-fetcher)

SerpFetcher
===========

[](#serpfetcher)

Wrapper around SimpleHtmlDom to easily fetch data from Search Engine Result Pages with built-in caching support.

Installing via Composer (recommended)
-------------------------------------

[](#installing-via-composer-recommended)

Install composer in your project:

```
curl -s http://getcomposer.org/installer | php

```

Create a composer.json file in your project root:

```
{
    "require": {
        "franzip/serp-fetcher": "0.2.*@dev"
    }
}

```

Install via composer

```
php composer.phar install

```

Supported Search Engines
------------------------

[](#supported-search-engines)

- Google
- Bing
- Ask
- Yahoo

Legal Disclaimer
----------------

[](#legal-disclaimer)

Under no circumstances I shall be considered liable to any user for direct, indirect, incidental, consequential, special, or exemplary damages, arising from or relating to userʹs use or misuse of this software. Consult the following Terms of Service before using SerpFetcher:

- [Google](https://www.google.com/accounts/TOS)
- [Bing](http://windows.microsoft.com/en-us/windows/microsoft-services-agreement)
- [Ask](http://about.ask.com/terms-of-service)
- [Yahoo](https://info.yahoo.com/legal/us/yahoo/utos/en-us/)

Description
-----------

[](#description)

You can create a SerpFetcher using both the provided Factory or importing the fetcher you need directly into your namespace.

All the various implementations share a common abstract ancestor class `SerpFetcher`, and therefore expose five main configurable attributes through setters:

```
SerpFetcher($cacheDir = 'cache', $cacheTTL = 24, $caching = true,
            $cachingForever = false, $charset = 'UTF-8')
```

1. `$cacheDir`
    - Path to the folder to use as temporary cache.
    - You can specify an absolute or relative path.
    - If it doesn't exist, the folder will be automatically created on instantiation.
2. `$cacheTTL`
    - The expiration time of the cache, expressed in hours.
3. `$caching`
    - Flag if the object should use caching.
4. `$cacheForever`
    - Flag if the object should use permanent caching (cached pages will never expire).
5. `$charset`
    - Charset to use.
    - Note: **Only UTF-8 (used as default) has been tested so far.**

The main method `fetch()` implemented for each class returns an associative array with urls, snippets and titles for a given SERP url. If the array with fetched results has less than 10 entries, padding will be added to sum up to 10.

Constructor (using Factory)
---------------------------

[](#constructor-using-factory)

Supply the name of the search engine and you are ready to go. It is possible to pass an optional array with custom arguments.

```
use Franzip\SerpFetcher\SerpFetcherBuilder;

$googleFetcher = SerpFetcherBuilder::create('Google');
$askFetcher = SerpFetcherBuilder::create('Ask', array($cacheDir = 'foo/bar'));
$bingFetcher = SerpFetcherBuilder::create('Bing', array($cacheDir = 'baz',
                                                        $cacheTTL = 1));
...
```

Constructor (using Fetchers directly)
-------------------------------------

[](#constructor-using-fetchers-directly)

```
use Franzip\SerpFetcher\Fetchers\AskFetcher;
use Franzip\SerpFetcher\Fetchers\BingFetcher;
use Franzip\SerpFetcher\Fetchers\GoogleFetcher;

$googleFetcher = new GoogleFetcher();
$askFetcher = new AskFetcher('foo/bar');
$bingFetcher = new BingFetcher('baz', 1);
...
```

Basic Usage
-----------

[](#basic-usage)

```
use Franzip\SerpFetcher\SerpFetcherBuilder;

$googleFetcher = SerpFetcherBuilder::create('Google');
$urlToFetch = 'http://www.google.com/search?q=foo';
$fetchedResults = $googleFetcher->fetch($urlToFetch);
// doing your things with the results...
```

cacheHit()
----------

[](#cachehit)

Your code can handle cache hit and cache miss.

```
use Franzip\SerpFetcher\SerpFetcherBuilder;

$googleFetcher = SerpFetcherBuilder::create('Google');
$urlToFetch = 'http://www.google.com/search?q=foo';
var_dump($googleFetcher->cacheHit($urlToFetch));
// bool(false)
$fetchedResults = $googleFetcher->fetch('http://www.google.com/search?q=foo');
var_dump($googleFetcher->cacheHit($urlToFetch));
// bool(true)

if ($googleFetcher->cacheHit($urlToFetch)) {
    // handle cache hit
} else {
    // handle cache miss
}
```

flushCache() and removeCache()
------------------------------

[](#flushcache-and-removecache)

Each fetched url get cached as a single file. You can remove all those files by calling `flushCache()`. `removeCache()` will also remove the folder used as cache.

```
use Franzip\SerpFetcher\SerpFetcherBuilder;

$googleFetcher = SerpFetcherBuilder::create('Google');
$urlToFetch = 'http://www.google.com/search?q=foo';
var_dump($googleFetcher->cacheHit($urlToFetch));
// bool(false)
$fetchedResults = $googleFetcher->fetch('http://www.google.com/search?q=foo');
var_dump($googleFetcher->cacheHit($urlToFetch));
// bool(true)
$googleFetcher->flushCache();
var_dump($googleFetcher->cacheHit($urlToFetch));
// bool(false)
```

Fine Tuning (Setters)
---------------------

[](#fine-tuning-setters)

```
use Franzip\SerpFetcher\SerpFetcherBuilder;

$googleFetcher = SerpFetcherBuilder::create('Google');
// change cache folder to foo/
$googleFetcher->setCacheDir('foo');
// change cache expiration to 2 days
$googleFetcher->setCacheTTL(48);
// enable permanent caching
$googleFetcher->enableCachingForever();
```

Using multiple cache directories
--------------------------------

[](#using-multiple-cache-directories)

Just switch between folders with the `setCacheDir()` method

```
use Franzip\SerpFetcher\SerpFetcherBuilder;

$googleFetcher = SerpFetcherBuilder::create('Google',
                                            array('foo'));
// fetch some stuff... foo/ will be used as cache folder now
...
// fetched results will now be cached in foobar/
$googleFetcher->setCacheDir('foobar');
// switch back to the initial cache folder foo/
$googleFetcher->setCacheDir('foo');
```

TODOs
-----

[](#todos)

- A decent exceptions system.
- Support for HHVM.
- Implement and test different charset support.
- Refactoring messy tests.

License
-------

[](#license)

[MIT](http://opensource.org/licenses/MIT/ "MIT") Public License.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/815354e0dcecb447e841e032ed3f02a985239704fbbebbd6cd48c360efed5b95?d=identicon)[franzip](/maintainers/franzip)

---

Top Contributors

[![franzip](https://avatars.githubusercontent.com/u/6237296?v=4)](https://github.com/franzip "franzip (38 commits)")

### Embed Badge

![Health badge](/badges/franzip-serp-fetcher/health.svg)

```
[![Health](https://phpackages.com/badges/franzip-serp-fetcher/health.svg)](https://phpackages.com/packages/franzip-serp-fetcher)
```

###  Alternatives

[gossi/php-code-generator

Toolset for generating PHP code

155206.9k33](/packages/gossi-php-code-generator)[dragon-code/benchmark

Simple comparison of code execution speed between different options

12037.9k6](/packages/dragon-code-benchmark)[askvortsov/flarum-auto-moderator

Powerful automation engine.

1419.4k2](/packages/askvortsov-flarum-auto-moderator)[ammardaana/laravel-domain-driven-design

Generate laravel Domain driven design (monolith) structure

111.8k](/packages/ammardaana-laravel-domain-driven-design)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
