PHPackages                             serpapi/serpapi-php - 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. serpapi/serpapi-php

ActiveLibrary

serpapi/serpapi-php
===================

Get Google, Bing, Baidu, eBay, Yahoo, Yandex, Home Depot, Naver, Apple, DuckDuckGo, Yelp and YouTube search results via SerpApi.com

10[2 PRs](https://github.com/serpapi/serpapi-php/pulls)PHPCI passing

Since Aug 13Pushed today5 watchersCompare

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

READMEChangelogDependenciesVersions (4)Used By (0)

SerpApi PHP Library
===================

[](#serpapi-php-library)

[![Packagist Version](https://camo.githubusercontent.com/4bca987dea105234fa56aa4232d318c5e0af5d1da6e5ded24c08dbff869eee0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736572706170692f736572706170692d7068702e7376673f6c6162656c3d7061636b6167697374)](https://packagist.org/packages/serpapi/serpapi-php)[![PHP](https://camo.githubusercontent.com/2f335ef09e13cb65b2a21e7759879e6123cd1d3d8bb9f4a0fff39e40ccfc42b1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e322d627269676874677265656e2e737667)](https://www.php.net)[![License: MIT](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/serpapi/serpapi-php/blob/master/MIT-LICENSE.txt)

Integrate search data into your PHP application. This library is the official wrapper for [SerpApi](https://serpapi.com).

SerpApi supports Google, Google Maps, Google Shopping, Baidu, Yandex, Yahoo, eBay, App Stores, and [more](https://serpapi.com).

This is the new library provided by SerpApi as a replacement for our old library that can be found [here](https://github.com/serpapi/google-search-results-php). Feel free to contact us in case you need any help:

[The full documentation is available here.](https://serpapi.com/search-api)

The following services are provided:

- [Search API](https://serpapi.com/search-api)
- [Location API](https://serpapi.com/locations-api)
- [Search Archive API](https://serpapi.com/search-archive-api)
- [Account API](https://serpapi.com/account-api)

SerpApi provides a [script builder](https://serpapi.com/playground) to get you started quickly.

Installation
------------

[](#installation)

PHP 7.2+ with `ext-curl` and `ext-json` must be installed along with [composer](https://getcomposer.org/) dependency management tool.

Tested PHP versions:

- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3
- 8.4
- 8.5

Package available from [packagist](https://packagist.org/packages/serpapi/serpapi-php).

Quick start
-----------

[](#quick-start)

```
composer require serpapi/serpapi-php
```

Simple Usage
------------

[](#simple-usage)

```
require 'vendor/autoload.php';

use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'q' => 'coffee',
]);

print_r($results->organic_results);
```

This example runs a search for "coffee" on Google. It returns the results as a PHP object decoded from JSON.

See the [playground](https://serpapi.com/playground) to generate your own code.

Configuration
-------------

[](#configuration)

### API key

[](#api-key)

The API key can be set in the constructor or later via `setApiKey`:

```
use SerpApi\Client;

// via constructor
$client = new Client('Your Private Key');

// or later
$client = new Client();
$client->setApiKey('Your Private Key');
```

Get your API key from [serpapi.com/dashboard](https://serpapi.com/dashboard).

### Engine

[](#engine)

The default engine is `google`. You can change it via the second constructor parameter:

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'), 'bing');
$results = $client->search(['q' => 'coffee']);
```

### Timeout

[](#timeout)

The default request timeout is 120 seconds. Customize it via the third constructor parameter:

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'), 'google', 30);
```

Search API
----------

[](#search-api)

### Search Google

[](#search-google)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google',
  'tbm' => 'isch',
  'q' => 'coffee',
]);

print_r($results->images_results);
```

- source: [tests/ExampleSearchGoogleTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGoogleTest.php)see:

### Search Google Scholar

[](#search-google-scholar)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google_scholar',
  'q' => 'coffee',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchGoogleScholarTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGoogleScholarTest.php)see:

### Search Google Autocomplete

[](#search-google-autocomplete)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google_autocomplete',
  'q' => 'coffee',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchGoogleAutocompleteTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGoogleAutocompleteTest.php)see:

### Search Google Shopping

[](#search-google-shopping)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google_shopping',
  'q' => 'coffee',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchGoogleShoppingTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGoogleShoppingTest.php)see:

### Search Google Maps

[](#search-google-maps)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google_maps',
  'q' => 'pizza',
  'll' => '@40.7455096,-74.0083012,15.1z',
  'type' => 'search',
]);

print_r($results->local_results);
```

- source: [tests/ExampleSearchGoogleMapsTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGoogleMapsTest.php)see:

### Search Google Jobs

[](#search-google-jobs)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google_jobs',
  'q' => 'coffee',
]);

print_r($results->jobs_results);
```

- source: [tests/ExampleSearchGoogleJobsTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGoogleJobsTest.php)see:

### Search Google Events

[](#search-google-events)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google_events',
  'q' => 'Events in Austin',
  'location' => 'Austin, Texas, United States',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchGoogleEventsTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGoogleEventsTest.php)see:

### Search Google Lens

[](#search-google-lens)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google_lens',
  'url' => 'https://i.imgur.com/5bGzZi7.jpg',
  'gl' => 'us',
  'hl' => 'en',
]);

print_r($results->visual_matches);
```

- source: [tests/ExampleSearchGoogleLensTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGoogleLensTest.php)see:

### Search Google Play

[](#search-google-play)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google_play',
  'q' => 'kite',
  'store' => 'apps',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchGooglePlayTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGooglePlayTest.php)see:

### Search Google Local Services

[](#search-google-local-services)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'google_local_services',
  'q' => 'electrician',
  'data_cid' => '6745062158417646970',
]);

print_r($results->local_ads);
```

- source: [tests/ExampleSearchGoogleLocalServicesTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchGoogleLocalServicesTest.php)see:

### Search Bing

[](#search-bing)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'bing',
  'q' => 'coffee',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchBingTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchBingTest.php)see:

### Search Baidu

[](#search-baidu)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'baidu',
  'q' => 'coffee',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchBaiduTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchBaiduTest.php)see:

### Search Yahoo

[](#search-yahoo)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'yahoo',
  'p' => 'coffee',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchYahooTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchYahooTest.php)see:

### Search YouTube

[](#search-youtube)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'youtube',
  'search_query' => 'coffee',
]);

print_r($results->video_results);
```

- source: [tests/ExampleSearchYoutubeTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchYoutubeTest.php)see:

### Search Walmart

[](#search-walmart)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'walmart',
  'query' => 'coffee',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchWalmartTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchWalmartTest.php)see:

### Search eBay

[](#search-ebay)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'ebay',
  '_nkw' => 'water',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchEbayTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchEbayTest.php)see:

### Search Naver

[](#search-naver)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'naver',
  'query' => 'coffee',
]);

print_r($results->ads_results);
```

- source: [tests/ExampleSearchNaverTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchNaverTest.php)see:

### Search Home Depot

[](#search-home-depot)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'home_depot',
  'q' => 'table',
]);

print_r($results->products);
```

- source: [tests/ExampleSearchHomeDepotTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchHomeDepotTest.php)see:

### Search Apple App Store

[](#search-apple-app-store)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'apple_app_store',
  'term' => 'coffee',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchAppleAppStoreTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchAppleAppStoreTest.php)see:

### Search DuckDuckGo

[](#search-duckduckgo)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'engine' => 'duckduckgo',
  'q' => 'coffee',
]);

print_r($results->organic_results);
```

- source: [tests/ExampleSearchDuckduckgoTest.php](https://github.com/serpapi/serpapi-php/blob/master/tests/ExampleSearchDuckduckgoTest.php)see:

APIs supported
--------------

[](#apis-supported)

### Location API

[](#location-api)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$locations = $client->location(['q' => 'Austin', 'limit' => 3]);

echo "Number of locations: " . count($locations) . "\n";
print_r($locations);
```

NOTE: `api_key` is not required for this endpoint.

### Search Archive API

[](#search-archive-api)

First, run a search and save the search ID:

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$results = $client->search([
  'q' => 'Coffee',
  'location' => 'Austin, Texas',
]);
$search_id = $results->search_metadata->id;
```

Now retrieve the previous search from the archive (free of charge):

```
$archived = $client->searchArchive($search_id);
print_r($archived);
```

### Account API

[](#account-api)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$account = $client->account();
print_r($account);
```

### HTML results

[](#html-results)

```
use SerpApi\Client;

$client = new Client(getenv('API_KEY'));
$html = $client->html(['q' => 'Coffee']);

echo strlen($html) . " bytes of HTML\n";
```

Error handling
--------------

[](#error-handling)

`SerpApiException` includes structured context for HTTP and API errors (status code, endpoint, search params, search id).

```
use SerpApi\Client;
use SerpApi\SerpApiException;

try {
  $client = new Client('invalid_key');
  $client->search(['q' => 'test']);
} catch (SerpApiException $exception) {
  echo $exception->getMessage() . "\n";
  // HTTP request failed with status: 401 error: Invalid API key... from url: https://serpapi.com/search

  echo $exception->getSerpApiError() . "\n";
  echo $exception->getResponseStatus() . "\n";
  echo $exception->getSearchId() . "\n";
  print_r($exception->getSearchParams());
  print_r($exception->toArray());
}
```

Testing
-------

[](#testing)

We love "true open source", "continuous integration", and Test Driven Development (TDD). We use PHPUnit to test our infrastructure around the clock using [GitHub Actions](https://github.com/serpapi/serpapi-php/actions/workflows/serpapi-php.yml) to achieve the best QoS (Quality Of Service).

The `tests/` directory includes specifications which serve the dual purposes of examples and functional tests.

Set your secret API key in your shell before running tests:

```
export API_KEY="your_secret_key"
```

Install dependencies and run the test suite:

```
make install
make test
```

Contributions are welcome. Feel free to submit a pull request!

Change log
----------

[](#change-log)

- 1.0 - First stable version

Conclusion
----------

[](#conclusion)

SerpApi supports all the major search engines. Google has the more advanced support with all the major services available: Images, News, Shopping and more...

[The full documentation is available here.](https://serpapi.com/search-api)

Authors: Victor Benarbia , Alaa Abdulridha For more information:

License
-------

[](#license)

[MIT](MIT-LICENSE.txt)

###  Health Score

23

—

LowBetter than 25% of packages

Maintenance65

Regular maintenance activity

Popularity2

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 78.8% 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/be1fa5ddeab7de5ad758d6fd7e3156b29999d2b97adff7c6674f474f2fc6dd31?d=identicon)[serpapi](/maintainers/serpapi)

---

Top Contributors

[![galetahub](https://avatars.githubusercontent.com/u/50163?v=4)](https://github.com/galetahub "galetahub (82 commits)")[![Alaa-abdulridha](https://avatars.githubusercontent.com/u/53356539?v=4)](https://github.com/Alaa-abdulridha "Alaa-abdulridha (21 commits)")[![jvmvik](https://avatars.githubusercontent.com/u/330204?v=4)](https://github.com/jvmvik "jvmvik (1 commits)")

### Embed Badge

![Health badge](/badges/serpapi-serpapi-php/health.svg)

```
[![Health](https://phpackages.com/badges/serpapi-serpapi-php/health.svg)](https://phpackages.com/packages/serpapi-serpapi-php)
```

PHPackages © 2026

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