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.2(1mo ago)43MITPHPPHP ^8.2CI passing

Since May 12Pushed 1mo 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 1w ago

READMEChangelog (3)Dependencies (30)Versions (4)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)

[Sign up](https://webscraping.ai/auth/sign_up) to get an API key — the free trial includes 2,000 credits, no credit card required. Your key lives in the [dashboard](https://webscraping.ai/dashboard).

```
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
```

Links
-----

[](#links)

- [WebScraping.AI](https://webscraping.ai) — features, pricing, signup
- [API documentation](https://webscraping.ai/docs)
- [Dashboard](https://webscraping.ai/dashboard) — API key, usage, request builder
- Other official clients: [Python](https://github.com/webscraping-ai/webscraping-ai-python) · [JavaScript](https://github.com/webscraping-ai/webscraping-ai-js) · [Ruby](https://github.com/webscraping-ai/webscraping-ai-ruby) · [Go](https://github.com/webscraping-ai/webscraping-ai-go) · [Java](https://github.com/webscraping-ai/webscraping-ai-java) · [.NET](https://github.com/webscraping-ai/webscraping-ai-dotnet) · [CLI](https://github.com/webscraping-ai/webscraping-ai-cli) · [MCP server](https://github.com/webscraping-ai/webscraping-ai-mcp-server) · [n8n node](https://github.com/webscraping-ai/webscraping-ai-n8n)
- Support:

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance94

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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 ~33 days

Total

3

Last Release

31d 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 (13 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.

36826.2k2](/packages/telnyx-telnyx-php)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

86337.5k](/packages/flow-php-flow)[openai-php/client

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

5.8k29.9M347](/packages/openai-php-client)[getbrevo/brevo-php

Official PHP SDK for the Brevo API.

1004.1M59](/packages/getbrevo-brevo-php)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.7k441.1k8](/packages/theodo-group-llphant)

PHPackages © 2026

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