PHPackages                             webscraping-ai/webscraping-ai-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. [API Development](/categories/api)
4. /
5. webscraping-ai/webscraping-ai-php

ActiveLibrary[API Development](/categories/api)

webscraping-ai/webscraping-ai-php
=================================

Official PHP client for the WebScraping.AI API — LLM-powered web scraping with rotating proxies and Chromium JavaScript rendering.

v4.0.1(1w ago)53MITPHPPHP ^8.2CI passing

Since May 12Pushed 1w ago2 watchersCompare

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

READMEChangelog (2)Dependencies (20)Versions (3)Used By (0)

WebScraping.AI PHP Client
=========================

[](#webscrapingai-php-client)

[![Packagist Version](https://camo.githubusercontent.com/e36c6acf3214733aa795b872c2d5273f09e8721a0e6d99f9d8d1f14fdcbad534/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765627363726170696e672d61692f7765627363726170696e672d61692d7068702e737667)](https://packagist.org/packages/webscraping-ai/webscraping-ai-php)[![CI](https://github.com/webscraping-ai/webscraping-ai-php/actions/workflows/ci.yml/badge.svg)](https://github.com/webscraping-ai/webscraping-ai-php/actions/workflows/ci.yml)

Official PHP client for the [WebScraping.AI](https://webscraping.ai) API.

The API gives you LLM-powered scraping tools with Chromium JavaScript rendering, rotating proxies, and built-in HTML parsing — full HTML, visible text, selected page areas, AI-extracted fields, and free-form question answering over any URL.

Requirements
------------

[](#requirements)

- PHP 8.2 or newer
- A [PSR-18 HTTP client](https://packagist.org/providers/psr/http-client-implementation) — Guzzle, Symfony HttpClient, or any other implementation
- A [PSR-17 message factory](https://packagist.org/providers/psr/http-factory-implementation)

If you don't already have these installed, the simplest pair is:

```
composer require guzzlehttp/guzzle nyholm/psr7
```

`php-http/discovery` (a transitive dependency) will pick them up automatically.

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

[](#installation)

```
composer require webscraping-ai/webscraping-ai-php
```

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

[](#quick-start)

```
use WebScrapingAI\Client;

$client = new Client(apiKey: getenv('WEBSCRAPING_AI_KEY'));

// Full HTML
$html = $client->html(url: 'https://example.com');

// Visible text
$text = $client->text(url: 'https://example.com');

// HTML for one selector
$h1 = $client->selected(url: 'https://example.com', selector: 'h1');

// HTML for multiple selectors (returns array)
$chunks = $client->selectedMultiple(
    url: 'https://example.com',
    selectors: ['h1', 'p', 'a'],
);

// LLM question over a page
$answer = $client->question(
    url: 'https://example.com',
    question: 'What is the main topic?',
);

// LLM-extracted structured fields
$fields = $client->fields(
    url: 'https://example.com',
    fields: [
        'title' => 'Main product title',
        'price' => 'Current price',
    ],
);

// Account quota
$account = $client->account();
```

All optional parameters (`headers`, `timeout`, `js`, `js_timeout`, `wait_for`, `proxy`, `country`, `custom_proxy`, `device`, `error_on_404`, `error_on_redirect`, `js_script`, …) are PHP named arguments. See [the API docs](https://webscraping.ai/docs) for the full parameter reference.

Bring your own HTTP client
--------------------------

[](#bring-your-own-http-client)

By default, the client builds its own transport. If Guzzle is installed it is used with a request deadline applied (see [Timeouts](#timeouts)); otherwise `php-http/discovery` resolves whatever PSR-18 client is installed. To pin a specific client, pass it explicitly:

```
use GuzzleHttp\Client as Guzzle;
use Nyholm\Psr7\Factory\Psr17Factory;
use WebScrapingAI\Client;

$factory = new Psr17Factory();
$client = new Client(
    apiKey: getenv('WEBSCRAPING_AI_KEY'),
    httpClient: new Guzzle(['timeout' => 30.0]),
    requestFactory: $factory,
    uriFactory: $factory,
);
```

Injecting your own client opts out of the default deadline — configure transport-level timeouts on the client you pass.

Timeouts
--------

[](#timeouts)

Two different timeouts are in play, and they're easy to confuse:

- The `timeout` parameter accepted by each endpoint method (`html()`, `text()`, …) controls **server-side page retrieval** — how long the API waits for the target page. It does not bound how long your HTTP client waits.
- The **transport timeout** bounds how long the PSR-18 client itself will wait on TCP connect and on reading the response body, so a stalled connection can't hang your process forever.

By default the client applies a transport deadline when it builds its own client and Guzzle is available: a total request timeout of `Client::DEFAULT_TIMEOUT` (60s) and a TCP connect timeout of `Client::DEFAULT_CONNECT_TIMEOUT` (10s). Override them via the constructor:

```
$client = new Client(
    apiKey: getenv('WEBSCRAPING_AI_KEY'),
    timeout: 120.0,        // total request deadline, seconds
    connectTimeout: 5.0,   // TCP connect deadline, seconds
);
```

These constructor timeouts apply **only** to the auto-built default client. If you inject your own `httpClient`, or no concrete client (Guzzle) is available and discovery falls back to an unknown PSR-18 implementation, no deadline is imposed — in that case inject a client with timeouts configured to get one.

Errors
------

[](#errors)

The client raises typed exceptions for every documented status code:

StatusException400`WebScrapingAI\Exception\BadRequestException`402`WebScrapingAI\Exception\PaymentRequiredException`403`WebScrapingAI\Exception\AuthenticationException`429`WebScrapingAI\Exception\RateLimitException`500`WebScrapingAI\Exception\ServerException`504`WebScrapingAI\Exception\GatewayTimeoutException`All inherit from `WebScrapingAI\Exception\ApiException`, which exposes `$message`, `$status`, `$statusCode`, `$statusMessage`, `$body`, and `$responseBody`. The latter three are populated when the API surfaces target-page errors as 500s.

Transport-level failures raise `WebScrapingAI\Exception\ApiTimeoutException` (the PSR-18 client timed out) or `WebScrapingAI\Exception\ApiConnectionException` (DNS / connection refused / TLS).

All SDK-originated exceptions implement the marker interface `WebScrapingAI\Exception\WebScrapingAIException`, so a single `catch (WebScrapingAIException $e)` block catches everything.

Response shapes
---------------

[](#response-shapes)

The client returns whatever the API returns — it does not normalise or unwrap. A couple of current quirks worth knowing:

- `fields()` returns `['result' => [...fields...]]` (the live API wraps the extracted fields under a `result` key).
- `selectedMultiple()` returns `array` — an outer wrapper containing all matched chunks concatenated.

These are upstream spec/server drifts; the official Ruby and Python clients return the same shapes.

Migration from 3.x
------------------

[](#migration-from-3x)

3.x was generated from the OpenAPI spec under the namespace `OpenAPI\Client\` and used per-tag classes (`AIApi`, `HTMLApi`, etc.). 4.0 is a hand-authored rewrite with a single `WebScrapingAI\Client` entry point. There are no deprecation shims — pin to `^3.2` if you need the old surface.

Development
-----------

[](#development)

```
composer install
composer test       # PHPUnit
composer lint       # php-cs-fixer (dry-run)
composer analyse    # PHPStan
```

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance98

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

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.

###  Release Activity

Cadence

Every ~40 days

Total

2

Last Release

12d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/71596876?v=4)[WebScraping.AI](/maintainers/webscraping-ai)[@webscraping-ai](https://github.com/webscraping-ai)

---

Top Contributors

[![webscraping-ai-bot](https://avatars.githubusercontent.com/u/62434457?v=4)](https://github.com/webscraping-ai-bot "webscraping-ai-bot (12 commits)")

---

Tags

apisdkcrawlerscrapingllmwebscraping

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k28.0M318](/packages/openai-php-client)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

1003.9M50](/packages/getbrevo-brevo-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M84](/packages/mollie-mollie-api-php)

PHPackages © 2026

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