> For the complete documentation index, see [llms.txt](https://docs.serphouse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.serphouse.com/official-sdks/php-sdk.md).

# PHP SDK

The official PHP SDK makes it easy to integrate the SERPHouse API into any PHP application.

It provides a clean interface for:

* Google SERP searches
* Scheduled SERP jobs
* Account information
* Supported domains
* Languages
* Locations

Instead of manually building HTTP requests, you interact with PHP methods while the SDK handles authentication and API communication.

<table data-view="cards"><thead><tr><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td>SERPHouse PHP SDK on GitHub</td><td><a href="https://github.com/SERPHouse/serphouse-php">https://github.com/SERPHouse/serphouse-php</a></td><td><a href="/files/Xq0oyQfrev32xggtwIRe">/files/Xq0oyQfrev32xggtwIRe</a></td></tr><tr><td>SERPHouse PHP SDK on Packagist</td><td><a href="https://packagist.org/packages/serphouse/serphouse-php">https://packagist.org/packages/serphouse/serphouse-php</a></td><td><a href="/files/R399K8DD5UsLX4Kp4BDq">/files/R399K8DD5UsLX4Kp4BDq</a></td></tr></tbody></table>

***

### Requirements

* PHP 7.2+
* Composer

***

### Installation

Install using Composer.

```
composer require serphouse/serphouse-php
```

***

### Get your API Key

Create a SERPHouse account and generate an API key from your dashboard.

### Initialize the Client

```php
require 'vendor/autoload.php';
use Serphouse\SERPHouseClient;
$client = new SERPHouseClient('YOUR_API_KEY');
```

That's all that's required before calling any endpoint.

***

### Live SERP Search

Retrieve Google search results instantly.

```php
$response = $client->serpApi->live([
    'data' => [
        'q' => 'apple',
        'domain' => 'google.com',
        'lang' => 'en',
        'device' => 'desktop',
        'serp_type' => 'web',
        'loc' => 'Texas, United States',
        'page' => 1,
        'num_result' => 10,
    ]
]);
```

***

### Schedule a Search

Instead of waiting for results immediately, schedule a search.

```php
$response = $client->serpApi->schedule([
    'data' => [
        [
            'q' => 'Coffee',
            'domain' => 'google.com',
            'lang' => 'en',
            'device' => 'desktop',
            'serp_type' => 'web',
            'loc' => 'Texas, United States',
            'postback_url' => '...',
            'pingback_url' => '...',
        ]
    ]
]);
```

***

### Check Search Status

```php
$response = $client->serpApi->check($searchId);
```

***

### Get Search Result

```php
$response = $client->serpApi->get($searchId);
```

Return HTML instead of JSON:

```php
$response = $client->serpApi->get($searchId, 'html');
```

***

### Domains

```php
$response = $client->domains->list();
```

***

### Languages

```php
$response = $client->languages->list();
```

For Bing:

```php
$response = $client->languages->list([
    'type' => 'bing'
]);
```

***

### Locations

```php
$response = $client->location->search([
    'q' => 'Texas'
]);
```

***

### Account

```php
$response = $client->account->fetch();
```

***

### Working with Responses

Every SDK call returns a `Responses` object.

Retrieve the HTTP status code:

```php
$response->getStatusCode();
```

Retrieve the API response:

```php
$response->getResponse();
```

Retrieve the error message:

```php
$response->getErrorMessage();
```

***

### Exception Handling

The SDK throws dedicated exception classes for common API errors.

```php
try {
    $response = $client->serpApi->live(...);
} catch (SERPHouseUnauthorizedException $e) {

}

catch (SERPHouseRateLimitExceededException $e) {

}

catch (SERPHouseServerErrorException $e) {

}
```

Supported exceptions include:

* `SERPHouseUnauthorizedException`
* `SERPHouseRateLimitExceededException`
* `SERPHousePaymentRequiredException`
* `SERPHouseNotFoundException`
* `SERPHouseServerErrorException`

***

### Support

If you encounter any issues while installing, configuring, or using the SERPHouse PHP SDK, we're here to help.

* Contact the SERPHouse support team for assistance.
* Report bugs or request features by opening an issue on the GitHub repository.

GitHub Repository:

<https://github.com/SERPHouse/serphouse-php>
