PHPackages                             serpapi/google-search-results-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. [HTTP &amp; Networking](/categories/http)
4. /
5. serpapi/google-search-results-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

serpapi/google-search-results-php
=================================

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

2.0(5y ago)69114.3k↓13.8%52[6 issues](https://github.com/serpapi/google-search-results-php/issues)MITPHPPHP ^5.5 || ^7.0CI failing

Since Mar 31Pushed 5mo ago11 watchersCompare

[ Source](https://github.com/serpapi/google-search-results-php)[ Packagist](https://packagist.org/packages/serpapi/google-search-results-php)[ Docs](http://github.com/serpapi/google-search-results-php)[ RSS](/packages/serpapi-google-search-results-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (7)Used By (0)

Google Search Results in PHP
============================

[](#google-search-results-in-php)

[![PHP build](https://github.com/serpapi/google-search-results-php/actions/workflows/test.yml/badge.svg)](https://github.com/serpapi/google-search-results-php/actions/workflows/test.yml)

This PHP API is meant to scrape and parse Google, Bing or Baidu results using [SerpApi](https://serpapi.com).

[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/demo) to get you started quickly.

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

[](#installation)

Php 7+ must be already installed and [composer](https://getcomposer.org/) dependency management tool.

Package available from packagist.

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

[](#quick-start)

if you're using composer, you can add this package ([link to packagist](https://packagist.org/packages/serpapi/google-search-results-php)).

```
$ composer require serpapi/google-search-results-php
```

Then you need to load the dependency in your script.

```

```

if not, you must clone this repository and link the class.

```
require 'path/to/google-search-results';
require 'path/to/restclient';
```

Get "your secret key" from

Then you can start coding something like:

```
$client = new GoogleSearch("your secret key");
$query = ["q" => "coffee","location"=>"Austin,Texas"];
$response = $client->get_json($query);
print_r($response);
```

This example runs a search about "coffee" using your secret api key.

The SerpApi service (backend)

- searches on Google using the query: q = "coffee"
- parses the messy HTML responses
- return a standardizes JSON response The Php class GoogleSearch
- Format the request to SerpApi server
- Execute GET http request
- Parse JSON into Ruby Hash using JSON standard library provided by Ruby Et voila..

Alternatively, you can search:

- Bing using BingSearch class
- Baidu using BaiduSearch class
- Ebay using EbaySearch class
- Yahoo using YahooSearch class
- Yandex using YandexSearch class
- Walmart using WalmartSearch class
- Youtube using YoutubeSearch class
- HomeDepot using HomeDepotSearch class
- Apple App Store using AppleAppStoreSearch class
- Naver using NaverSearch class

See the playground to generate your code.

Example
-------

[](#example)

- [How to set SERP API key](#how-to-set-serp-api-key)
- [Search API capability](#search-api-capability)
- [Location API](#location-api)
- [Search Archive API](#search-archive-api)
- [Account API](#account-api)
- [Search Google Images](#search-google-images)
- [Generic SerpApiClient](#serpapiclient)
- [Example by specification](#example-by-specification)
- [Composer example](#composer-example)

### How to set SERP API key

[](#how-to-set-serp-api-key)

The SerpApi api\_key can be set globally using a singleton pattern.

```
$client = new GoogleSearch();
$client->set_serp_api_key("Your Private Key");
```

Or

```
$client = new GoogleSearch("Your Private Key");
```

### Search API capability

[](#search-api-capability)

```
$query = [
  "q" =>  "query",
  "google_domain" =>  "Google Domain",
  "location" =>  "Location Requested",
  "device" =>  "device",
  "hl" =>  "Google UI Language",
  "gl" =>  "Google Country",
  "safe" =>  "Safe Search Flag",
  "start" =>  "Pagination Offset",
  "serp_api_key" =>  "Your SERP API Key",
  "tbm" => "nws|isch|shop"
  "tbs" => "custom to be search criteria"
  "async" => true|false # allow async
];

$client = new GoogleSearch("private key");

$html_results = $client->get_html($query);
$json_results = $client->get_json($query);
```

### Location API

[](#location-api)

```
$client = new GoogleSearch(getenv("API_KEY"));
$location_list = $client->get_location('Austin', 3);
print_r($location_list);
```

it prints the first 3 location matching Austin (Texas, Texas, Rochester)

```
[{:id=>"585069bdee19ad271e9bc072",
  :google_id=>200635,
  :google_parent_id=>21176,
  :name=>"Austin, TX",
  :canonical_name=>"Austin,TX,Texas,United States",
  :country_code=>"US",
  :target_type=>"DMA Region",
  :reach=>5560000,
  :gps=>[-97.7430608, 30.267153],
  :keys=>["austin", "tx", "texas", "united", "states"]},
  ...]
```

### Search Archive API

[](#search-archive-api)

Let's run a search to get a search\_id.

```
$client = new GoogleSearch(getenv("API_KEY"));
$result = $client->get_json($this->QUERY);
$search_id = $result->search_metadata->id
```

Now let's retrieve the previous search from the archive.

```
$archived_result = $client->get_search_archive($search_id);
print_r($archived_result);
```

it prints the search from the archive.

### Account API

[](#account-api)

```
$client = new GoogleSearch($this->API_KEY);
$info = $client->get_account();
print_r($info);
```

it prints your account information.

### Search Google Images

[](#search-google-images)

```
$client = new GoogleSearch(getenv("API_KEY"));
$data = $client->get_json([
  'q' => "Coffee",
  'tbm' => 'isch'
]);

foreach($data->images_results as $image_result) {
  print_r($image_result->original);
  //to download the image:
  // `wget #{image_result[:original]}`
}
```

this code prints all the images links, and download image if you un-comment the line with wget (linux/osx tool to download image).

Example by specification
------------------------

[](#example-by-specification)

The code described above is tested in the file test.php and example.php. To run the test locally.

```
export API_KEY='your secret key'
make test example
```

Composer example
----------------

[](#composer-example)

see: [https://github.com/serpapi/google-search-results-php/example\_composer/](https://github.com/serpapi/google-search-results-php/example_composer/)

To run the code.

- git clone
- cd google-search-results-php/example\_composer/
- make API\_KEY= all

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

[](#change-log)

- 2.0
    - Code refractoring SearchResult -&gt; Search
    - Add walmart and youtube search engine
- 1.2.0
    - Add more search engine
- 1.0
    - First stable version

Conclusion
----------

[](#conclusion)

SerpApi supports all the major search engines. Google has the more advance support with all the major services available: Images, News, Shopping and more.. To enable a type of search, the field tbm (to be matched) must be set to:

- isch: Google Images API.
- nws: Google News API.
- shop: Google Shopping API.
- any other Google service should work out of the box.
- (no tbm parameter): regular Google search. The field tbs allows to customize the search even more.

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

Author: Victor Benarbia For more information:

Thanks Rest API for Php

- Travis Dent -
- Test framework - PhpUnit -

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance47

Moderate activity, may be stable

Popularity49

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 74.2% 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.

###  Release Activity

Cadence

Every ~167 days

Total

4

Last Release

2102d ago

Major Versions

1.3.0.x-dev → 2.02020-08-15

PHP version history (2 changes)1.2.0.x-devPHP &gt;=5.4.0

2.0PHP ^5.5 || ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/be1fa5ddeab7de5ad758d6fd7e3156b29999d2b97adff7c6674f474f2fc6dd31?d=identicon)[serpapi](/maintainers/serpapi)

---

Top Contributors

[![jvmvik](https://avatars.githubusercontent.com/u/330204?v=4)](https://github.com/jvmvik "jvmvik (49 commits)")[![hartator](https://avatars.githubusercontent.com/u/307597?v=4)](https://github.com/hartator "hartator (3 commits)")[![atefBB](https://avatars.githubusercontent.com/u/10966925?v=4)](https://github.com/atefBB "atefBB (3 commits)")[![shubhamjain](https://avatars.githubusercontent.com/u/309760?v=4)](https://github.com/shubhamjain "shubhamjain (3 commits)")[![Alaa-abdulridha](https://avatars.githubusercontent.com/u/53356539?v=4)](https://github.com/Alaa-abdulridha "Alaa-abdulridha (2 commits)")[![evil1morty](https://avatars.githubusercontent.com/u/42971559?v=4)](https://github.com/evil1morty "evil1morty (1 commits)")[![exfriend](https://avatars.githubusercontent.com/u/769995?v=4)](https://github.com/exfriend "exfriend (1 commits)")[![encreinformatique](https://avatars.githubusercontent.com/u/22235605?v=4)](https://github.com/encreinformatique "encreinformatique (1 commits)")[![ilyazub](https://avatars.githubusercontent.com/u/282605?v=4)](https://github.com/ilyazub "ilyazub (1 commits)")[![drewroberts](https://avatars.githubusercontent.com/u/24581081?v=4)](https://github.com/drewroberts "drewroberts (1 commits)")[![dimitryzub](https://avatars.githubusercontent.com/u/78694043?v=4)](https://github.com/dimitryzub "dimitryzub (1 commits)")

---

Tags

phpphp-apiserp-apijsonapiclientsearchrestxmlcurlgoogleyoutuberesultwalmartyandexSERPlocalisation

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tcdent/php-restclient

A generic REST API client for PHP

3542.9M29](/packages/tcdent-php-restclient)[arhitector/yandex

PHP SDK для работы с некоторыми сервисами яндекса (Яндекс.Диск, Yandex.Disk)

13082.9k5](/packages/arhitector-yandex)[vinelab/http

An http library developed for the laravel framework. aliases itself as HttpClient

59300.2k11](/packages/vinelab-http)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)

PHPackages © 2026

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