承接 kelvinzer0/curl-impersonate-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kelvinzer0/curl-impersonate-php

Composer 安装命令:

composer require kelvinzer0/curl-impersonate-php

包简介

PHP wrapper for curl-impersonate — mimic real browser TLS fingerprints to bypass anti-bot detection

README 文档

README

curl-impersonate-php

Stop getting blocked. Start impersonating real browsers.

Latest Version CI PHP Version License Downloads Stars

PHP wrapper for curl-impersonate — execute HTTP requests that mimic real browser TLS fingerprints, bypassing Cloudflare, Akamai, Datadome, and other anti-bot systems.

Installation · Quick Start · Browser Presets · API · FAQ

Why This Exists

Regular curl has a distinct TLS fingerprint. Anti-bot systems detect it instantly.

curl-impersonate uses a patched libcurl that produces the exact same TLS ClientHello as Chrome, Firefox, or Safari. Your requests become indistinguishable from a real browser.

This library wraps it in a clean PHP API — no shell scripting required.

Regular curl    →  TLS fingerprint = "bot"     →  🚫 403 Blocked
curl-impersonate →  TLS fingerprint = "Chrome"  →  ✅ 200 OK

Installation

composer require kelvinzer0/curl-impersonate-php

Install curl-impersonate binary

# Linux x86_64 (v0.6.1)
curl -L https://github.com/lwthiker/curl-impersonate/releases/download/v0.6.1/curl-impersonate-v0.6.1.x86_64-linux-gnu.tar.gz | tar xz
export LD_LIBRARY_PATH="$PWD:$LD_LIBRARY_PATH"

# macOS (Homebrew)
brew install curl-impersonate

See curl-impersonate releases for all builds.

Quick Start

<?php
require 'vendor/autoload.php';

use CurlImpersonate\CurlImpersonate;

$curl = new CurlImpersonate();

// Option 1: Use a browser preset (auto-detects binary path)
$response = $curl
    ->setBrowser(CurlImpersonate::BROWSER_CHROME)
    ->setopt(CurlImpersonate::OPT_URL, 'https://example.com')
    ->setopt(CurlImpersonate::OPT_METHOD, 'GET')
    ->exec();

echo $response;
<?php
// Option 2: Point to a specific binary
$curl = new CurlImpersonate();
$response = $curl
    ->setopt(CurlImpersonate::OPT_URL, 'https://example.com')
    ->setopt(CurlImpersonate::OPT_ENGINE, '/path/to/curl_chrome116')
    ->exec();

Browser Presets

Preset Constant Mimics
Chrome 116 BROWSER_CHROME Chrome 116 on Windows 10
Chrome 120 BROWSER_CHROME_120 Chrome 120 on Windows 10
Firefox 102 BROWSER_FIREFOX Firefox 102 ESR on Linux
Firefox 117 BROWSER_FIREFOX_117 Firefox 117 on Linux
Safari 15.3 BROWSER_SAFARI Safari 15.3 on macOS Monterey
Safari 17.0 BROWSER_SAFARI_17 Safari 17.0 on macOS Sonoma
Edge 99 BROWSER_EDGE Edge 99 on Windows
$curl->setBrowser(CurlImpersonate::BROWSER_CHROME_120);

API

Options

$curl->setopt(int $option, mixed $value): self
Constant Description Example
OPT_URL Target URL 'https://api.example.com/data'
OPT_METHOD HTTP method 'POST'
OPT_POSTFIELDS Request body (array → JSON) ['key' => 'value']
OPT_HTTP_HEADERS Headers array ['Authorization: Bearer xxx']
OPT_HEADER Include response headers true
OPT_ENGINE Path to curl-impersonate binary '/usr/local/bin/curl_chrome116'
OPT_PROXY Proxy (HTTP or SOCKS5) 'socks5://127.0.0.1:1080'
OPT_TIMEOUT Request timeout (seconds) 30
OPT_FOLLOW_LOCATION Follow redirects true
OPT_VERIFY_SSL Verify SSL certificates true
OPT_COOKIEFILE Read cookies from file '/tmp/cookies.txt'
OPT_COOKIEJAR Save cookies to file '/tmp/cookies.txt'

Methods

// Execute and get response
$response = $curl->exec(): ?string

// Execute with streaming
$curl->execStream(): self
$chunk = $curl->readStream(4096): string|false
$curl->closeStream(): void

// Build command (for debugging)
$command = $curl->buildCommand(): string

// Reset for reuse
$curl->reset(): self

Examples

POST JSON with authentication

$curl = new CurlImpersonate();
$response = $curl
    ->setBrowser(CurlImpersonate::BROWSER_CHROME)
    ->setopt(CurlImpersonate::OPT_URL, 'https://api.example.com/users')
    ->setopt(CurlImpersonate::OPT_METHOD, 'POST')
    ->setopt(CurlImpersonate::OPT_POSTFIELDS, ['name' => 'Kelvin', 'role' => 'admin'])
    ->setopt(CurlImpersonate::OPT_HTTP_HEADERS, [
        'Authorization: Bearer YOUR_TOKEN',
        'Content-Type: application/json',
    ])
    ->exec();

SOCKS5 proxy

$curl = new CurlImpersonate();
$response = $curl
    ->setBrowser(CurlImpersonate::BROWSER_FIREFOX)
    ->setopt(CurlImpersonate::OPT_URL, 'https://check.torproject.org/api/ip')
    ->setopt(CurlImpersonate::OPT_PROXY, 'socks5h://127.0.0.1:9050')
    ->exec();

Stream large responses

$curl = new CurlImpersonate();
$curl
    ->setBrowser(CurlImpersonate::BROWSER_SAFARI)
    ->setopt(CurlImpersonate::OPT_URL, 'https://example.com/large-file')
    ->execStream();

while ($chunk = $curl->readStream(8192)) {
    echo $chunk; // process chunk by chunk
}

Scrape with cookies

$curl = new CurlImpersonate();

// Step 1: Login and save cookies
$curl
    ->setBrowser(CurlImpersonate::BROWSER_CHROME)
    ->setopt(CurlImpersonate::OPT_URL, 'https://example.com/login')
    ->setopt(CurlImpersonate::OPT_METHOD, 'POST')
    ->setopt(CurlImpersonate::OPT_POSTFIELDS, ['user' => 'admin', 'pass' => 'secret'])
    ->setopt(CurlImpersonate::OPT_COOKIEJAR, '/tmp/cookies.txt')
    ->exec();

// Step 2: Use saved cookies
$response = $curl
    ->reset()
    ->setBrowser(CurlImpersonate::BROWSER_CHROME)
    ->setopt(CurlImpersonate::OPT_URL, 'https://example.com/dashboard')
    ->setopt(CurlImpersonate::OPT_COOKIEFILE, '/tmp/cookies.txt')
    ->exec();

FAQ

Where do I get the curl-impersonate binary?

Download from releases or install via package manager:

# macOS
brew install curl-impersonate

# Arch Linux
yay -S curl-impersonate

# Docker
docker pull lwthiker/curl-impersonate:0.6.1

How do I use proxies?

Use OPT_PROXY with any proxy type curl supports:

// HTTP proxy
->setopt(CurlImpersonate::OPT_PROXY, 'http://user:pass@proxy.example.com:8080')

// SOCKS5 proxy
->setopt(CurlImpersonate::OPT_PROXY, 'socks5://127.0.0.1:1080')

// SOCKS5 with DNS resolution through proxy
->setopt(CurlImpersonate::OPT_PROXY, 'socks5h://127.0.0.1:1080')

I get "command not found" errors

Make sure curl-impersonate binaries are in your PATH or use the full path:

// Option 1: setBrowser with explicit path
->setBrowser(CurlImpersonate::BROWSER_CHROME, '/opt/curl-impersonate/bin')

// Option 2: direct engine path
->setopt(CurlImpersonate::OPT_ENGINE, '/opt/curl-impersonate/bin/curl_chrome116')

Does this work on shared hosting?

No. This library requires shell access to execute the curl-impersonate binary. It works on VPS, dedicated servers, Docker containers, and any environment where you can install system packages.

Comparison

Feature Native curl Guzzle This library
TLS fingerprint ❌ Bot detection ❌ Bot detection ✅ Real browser
HTTP/2 fingerprint ✅ Real browser
Ja3 fingerprint ✅ Matched
PHP API ❌ Raw resource ✅ Clean ✅ Clean
Proxy support
Streaming

Who Uses This

  • Web scraping at scale without IP rotation
  • SEO monitoring tools
  • Price comparison services
  • API integration with anti-bot protected endpoints
  • Security research and testing

Contributing

See CONTRIBUTING.md.

License

MIT © Kelvin Yuli Andrian

⭐ Star this repo if it saved you from 403s

Report Bug · Request Feature

kelvinzer0/curl-impersonate-php 适用场景与选型建议

kelvinzer0/curl-impersonate-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 57.42k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2023 年 07 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「curl」 「http」 「browser」 「http-client」 「impersonation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kelvinzer0/curl-impersonate-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kelvinzer0/curl-impersonate-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 kelvinzer0/curl-impersonate-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 57.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 25
  • 点击次数: 34
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 24
  • Watchers: 3
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-26