PHPackages                             meinlieberscholli/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. meinlieberscholli/google-search-results-php

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

meinlieberscholli/google-search-results-php
===========================================

Scrape Google, Bing, Baidu, Ebay, Youtube, Walmart, Yandex search result at scale using SerpApi.com

2.0.3(4y ago)0673MITPHPPHP ^8.0 || ^8.1

Since Mar 31Pushed 4y agoCompare

[ Source](https://github.com/MeinLieberScholli/google-search-results-php)[ Packagist](https://packagist.org/packages/meinlieberscholli/google-search-results-php)[ Docs](http://github.com/meinlieberscholli/google-search-results-php)[ RSS](/packages/meinlieberscholli-google-search-results-php/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (1)Versions (8)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($json_results)
```

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

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",
  "num" =>  "Number of Results",
  "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($this->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($this->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($this->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

33

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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 ~166 days

Recently: every ~210 days

Total

7

Last Release

1551d ago

Major Versions

1.3.0.x-dev → 2.02020-08-15

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

2.0PHP ^5.5 || ^7.0

2.0.1PHP ^5.5 || ^7.0 || ^8.0

2.0.3PHP ^8.0 || ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/27cc5c7d1c0592ce1a5c54d42673ce9ef65a2aa5af646db177be7994352c4954?d=identicon)[MeinLieberScholli](/maintainers/MeinLieberScholli)

---

Top Contributors

[![jvmvik](https://avatars.githubusercontent.com/u/330204?v=4)](https://github.com/jvmvik "jvmvik (42 commits)")[![atefBB](https://avatars.githubusercontent.com/u/10966925?v=4)](https://github.com/atefBB "atefBB (3 commits)")[![hartator](https://avatars.githubusercontent.com/u/307597?v=4)](https://github.com/hartator "hartator (2 commits)")[![exfriend](https://avatars.githubusercontent.com/u/769995?v=4)](https://github.com/exfriend "exfriend (1 commits)")

---

Tags

jsonapiclientsearchrestxmlcurlgoogleyoutuberesultwalmartyandexSERPlocalisation

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[serpapi/google-search-results-php

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

69110.0k](/packages/serpapi-google-search-results-php)[tcdent/php-restclient

A generic REST API client for PHP

3552.9M22](/packages/tcdent-php-restclient)[arhitector/yandex

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

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

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

57299.6k10](/packages/vinelab-http)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4639.8k](/packages/ismaeltoe-osms)

PHPackages © 2026

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