{"id":27323,"date":"2026-11-11T05:15:34","date_gmt":"2026-11-11T05:15:34","guid":{"rendered":"https:\/\/capskip.com\/?p=27323"},"modified":"2026-11-11T05:15:34","modified_gmt":"2026-11-11T05:15:34","slug":"hcaptcha-php","status":"publish","type":"post","link":"https:\/\/capskip.com\/zh\/hcaptcha-php\/","title":{"rendered":"PHP \u4e2d\u7684 hCaptcha\uff1a\u7528 CapSkip SDK \u548c Guzzle \u8bc6\u522b"},"content":{"rendered":"<p>To solve hCaptcha in PHP, install capskip\/capskip and call hcaptcha() with the sitekey and the page address. The <a href=\"https:\/\/capskip.com\/hcaptcha-solver\/\">CapSkip hCaptcha solver<\/a> returns a token plus the User-Agent it was earned with. The PHP part is the clock: a solve takes 10 to 30 seconds per the CapSkip docs, the SDK waits up to 300 unless you pass a timeout, and PHP ends a web request after 30. This guide fits the timeout inside that limit, then posts the form with Guzzle.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">What you need<\/h2>\n<ul>\n<li>A Windows machine with CapSkip 4.0.0 or newer, the first version that handles hCaptcha.<\/li>\n<li>Composer and PHP 8.0.2 or newer, with the curl and json extensions enabled. The SDK asks for 8.0, and on 8.0.30 Composer&#8217;s platform check for the SDK plus Guzzle says 8.0.2. The hcaptcha method arrived in SDK version 1.6.0. I ran PHP 8.0.30, 8.1.33, 8.2.29, 8.3.28, 8.4.15 and 8.5.0 for Windows, each with Guzzle 7.16.1 and with Guzzle 8.3.0.<\/li>\n<li>A form guarded by an hCaptcha widget that you are allowed to automate, and the widget&#8217;s sitekey.<\/li>\n<li>A way to reach CapSkip. Local mode answers only on the PC it runs on (127.0.0.1). Server mode also answers on your network or public IP. The <a href=\"https:\/\/capskip.com\/setup-guide\/#connection-settings\">connection settings<\/a> are where you pick the mode.<\/li>\n<\/ul>\n<div data-no-translation>\n<pre data-enlighter-language=\"bash\" class=\"EnlighterJSRAW\"># In a PowerShell prompt, in the folder that will hold hcaptcha_form.php\ncomposer require capskip\/capskip guzzlehttp\/guzzle<\/pre>\n<\/div>\n<p>How it was tested: against a mock of in.php and res.php that I wrote from the hCaptcha section of the <a href=\"https:\/\/capskip.com\/api-docs\/#hcaptcha\">API docs<\/a>, with a fake sign-up page beside it. No request went to a real CapSkip app or hCaptcha site, so every solve time below is a mock setting and the page&#8217;s checks (one use per token, a matching User-Agent, a two minute lifetime) are the docs&#8217; rules as I coded them. The PHP side is real: the SDK, Guzzle and PHP on Windows, on the command line and under the built-in web server, not Apache or IIS. The hCaptcha <a href=\"https:\/\/docs.hcaptcha.com\/\" rel=\"noopener nofollow\" target=\"_blank\">developer docs<\/a> cover real verification.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Step 1: call hcaptcha() with a timeout of your own<\/h2>\n<p>Put the four PHP blocks into one file named hcaptcha_form.php, in the order shown. The sitekey is a data-sitekey attribute on the h-captcha container, the sitekey option of hcaptcha.render(), or the sitekey= parameter of the widget&#8217;s iframe address. Paste it into SITEKEY and set PAGE_URL.<\/p>\n<p>The method is hcaptcha(string $sitekey, string $url, array $options = []). The options array takes the keys &quot;timeout&quot;, &quot;invisible&quot; (1 or true), &quot;data&quot; (the rqdata value of an Enterprise site), &quot;userAgent&quot; and &quot;proxy&quot;. Before it sends anything, the SDK refuses a blank sitekey, a page address that is not absolute http or https, an invisible value other than 0, 1, true or false, and any option CapSkip does not take, the domain option of 2Captcha among them. Each refusal is a ValidationException.<\/p>\n<p>The returned array has a &quot;token&quot; entry for h-captcha-response and g-recaptcha-response, a &quot;code&quot; entry with the same string, a &quot;userAgent&quot; entry and a &quot;captchaId&quot; entry. Its &quot;respKey&quot; entry is hCaptcha&#8217;s second value, empty when there is none, and most sites never read it. The task_options function is where the invisible or data keys go, and it runs for every task, because an rqdata value is single use. With API Key Validation on, add an &quot;apiKey&quot; key to the constructor array.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">&lt;?php\n\/\/ hcaptcha_form.php: run it with php hcaptcha_form.php\ndeclare(strict_types=1);\n\nrequire __DIR__ . '\/vendor\/autoload.php';\n\nuse CapSkip\\CapSkip;\nuse CapSkip\\Exceptions\\ApiException;\nuse CapSkip\\Exceptions\\CapSkipError;\nuse CapSkip\\Exceptions\\TimeoutException;\nuse GuzzleHttp\\Client;\nuse GuzzleHttp\\Cookie\\CookieJar;\n\nconst PAGE_URL = 'https:\/\/example.com\/signup';  \/\/ the page that shows the widget\nconst SITEKEY = 'YOUR_SITEKEY';  \/\/ the data-sitekey of its h-captcha div\nconst BUDGET = 90;  \/\/ seconds one sign-up may spend waiting for tokens\n\n\/\/ Local mode. In Server mode, use your server's address instead. With API Key\n\/\/ Validation on, add 'apiKey' =&gt; 'YOUR_KEY' to this array.\n$solver = new CapSkip(['host' =&gt; '127.0.0.1', 'port' =&gt; 8080]);\n\n\/\/ Extra task options, asked for on every task, so a fresh value fits here.\n\/\/   invisible widget:  return ['invisible' =&gt; 1];\n\/\/   Enterprise rqdata: return ['data' =&gt; fetch_rqdata()];  (your own function)\nfunction task_options(): array\n{\n    return [];\n}\n\nfunction solve(CapSkip $solver, float $deadline): array\n{\n    $left = (int) floor($deadline - microtime(true));\n    if ($left &lt; 10) {\n        \/\/ Not enough time for a solve. A timeout of 0 would mean the SDK default.\n        throw new TimeoutException('the budget is used up');\n    }\n    \/\/ Waits for the token. The result holds token (for h-captcha-response and\n    \/\/ g-recaptcha-response), code (the same string), userAgent (the browser\n    \/\/ identity of the token), respKey (empty when there is none) and captchaId.\n    return $solver-&gt;hcaptcha(SITEKEY, PAGE_URL, ['timeout' =&gt; $left] + task_options());\n}<\/pre>\n<\/div>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Step 2: keep the wait inside PHP&#8217;s time limit<\/h2>\n<p>The hcaptcha() call blocks. It submits the task, then polls until the token is ready or the timeout ends. A web request gets 30 seconds of max_execution_time, but the command line gets none: its limit read 0 here even with 30 in php.ini, while PHP&#8217;s built-in web server read 30. I used a 5 second limit on Windows, and PHP 8.0.30, 8.4.15 and 8.5.0 behaved the same.<\/p>\n<table>\n<thead>\n<tr>\n<th>What I ran under a 5 second limit<\/th>\n<th>What happened<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>A single sleep of 10 seconds<\/td>\n<td>The fatal error came at 10.0 seconds, when the sleep returned<\/td>\n<\/tr>\n<tr>\n<td>Sleeping in steps of 0.25 seconds<\/td>\n<td>The fatal error came at 5.2 seconds<\/td>\n<\/tr>\n<tr>\n<td>The hcaptcha() call on a task that never finished<\/td>\n<td>The fatal error came at 7.8 seconds, when the SDK&#8217;s sleep from 3.8 to 7.8 seconds returned<\/td>\n<\/tr>\n<tr>\n<td>A try block with catch and finally around the sleep<\/td>\n<td>Neither ran. A function from register_shutdown_function did, and error_get_last held the message<\/td>\n<\/tr>\n<tr>\n<td>set_time_limit(5) after 3 seconds, then a 4 second sleep<\/td>\n<td>No error. The script ran 7.0 seconds in total<\/td>\n<\/tr>\n<tr>\n<td>set_time_limit(0) after 2 seconds, with a 3 second limit, then a 5 second sleep<\/td>\n<td>No error. The script ran 7.0 seconds in total<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Three rules follow. PHP never interrupts a sleep or a cURL call, which is all the SDK does while it waits. It checks the limit when control returns, so a wait can overshoot by its full length. A fatal error skips catch and finally, so no handler of yours can save the job. And set_time_limit restarts the counter instead of adding to it. I ran Windows only, and the <a href=\"https:\/\/www.php.net\/manual\/en\/function.set-time-limit.php\" rel=\"noopener nofollow\" target=\"_blank\">PHP manual for set_time_limit<\/a> says other systems do not count sleeping or waiting on a socket.<\/p>\n<p>The SDK&#8217;s polling decides the rest, as read in its source and checked against the mock. The first poll goes out at once, then it sleeps 0.25 seconds, 0.5, 1, 2 and 4, and after that 5 between polls. The timeout is a deadline for starting a poll, not for the answer. With a timeout of 20 the last poll went out at 17.8 seconds and the TimeoutException came at 22.9, so a token that became ready at 19 seconds was never read. A timeout of 0 falls back to the SDK&#8217;s defaultTimeout of 120 seconds, which the solve function avoids.<\/p>\n<p>BUDGET is therefore the one number you own: how long a sign-up may wait for tokens, shared by all attempts. Step 4 gives PHP BUDGET plus 30 seconds, so your deadline fires first, as a TimeoutException you can catch, never as a fatal error you can&#8217;t. Keep BUDGET under any web server timeout in front of PHP, which set_time_limit does not touch. CapSkip may also hold a task for a free hCaptcha thread, up to 250 seconds in the app source I read, so raise BUDGET together with PHP&#8217;s limit if you queue many solves.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Step 3: post the form with the cookie jar and the right User-Agent<\/h2>\n<p>The page load and the post must look like one visitor. A Guzzle client keeps no cookies unless you give it a jar, so post_form builds a client with a new CookieJar, loads the page and posts with the cookies the page set.<\/p>\n<p>The token also belongs to a browser identity. The docs say the reply names the User-Agent that CapSkip solved with, and the form must be posted under it. Guzzle would announce itself instead: the mock saw GuzzleHttp\/8 (GuzzleHttp\/7 under Guzzle 7) on the page load when the header was left out, and it refused the post. A default User-Agent on the site client covers both requests, so that client is created after the solve. The &quot;userAgent&quot; key does not change that, because the docs say CapSkip uses it only when it matches its own browser.<\/p>\n<p>The post sends the page address as Referer. Guzzle adds none, and some frameworks, Django among them, refuse an HTTPS form post with neither Referer nor Origin. A mock site with that rule answered 403 until the header was there. The hidden_fields function copies the form&#8217;s hidden inputs, a CSRF token for one. Its loadHTML prefix makes libxml read UTF-8: without it, on a page with no meta charset tag, an accented letter in a hidden value arrived garbled and the mock refused the post. The widget fills both h-captcha-response and g-recaptcha-response, so the code sends both.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function hidden_fields(string $html): array\n{\n    $doc = new DOMDocument();\n    libxml_use_internal_errors(true);\n    \/\/ The prefix makes libxml read the page as UTF-8 even without a meta tag.\n    $doc-&gt;loadHTML('&lt;?xml encoding=&quot;UTF-8&quot;&gt;' . $html);\n    $fields = [];\n    foreach ((new DOMXPath($doc))-&gt;query('\/\/form\/\/input[@type=&quot;hidden&quot;][@name]') as $input) {\n        $fields[$input-&gt;getAttribute('name')] = $input-&gt;getAttribute('value');\n    }\n    return $fields;\n}\n\nfunction post_form(array $solved, string $email): int\n{\n    \/\/ The SDK adds userAgent only when CapSkip's reply names one. Never fall\n    \/\/ back to Guzzle's own: the token belongs to the browser that earned it.\n    $userAgent = $solved['userAgent'] ?? throw new RuntimeException('CapSkip named no User-Agent');\n    \/\/ One client for the page load and the post: its jar keeps the session\n    \/\/ cookie, and its default header is the User-Agent the token was earned with.\n    $site = new Client([\n        'cookies' =&gt; new CookieJar(),\n        'headers' =&gt; ['User-Agent' =&gt; $userAgent],\n        'http_errors' =&gt; false,\n        'timeout' =&gt; 20,\n    ]);\n    $page = $site-&gt;get(PAGE_URL);\n    if ($page-&gt;getStatusCode() !== 200) {\n        throw new RuntimeException('GET ' . PAGE_URL . ' answered ' . $page-&gt;getStatusCode());\n    }\n    $fields = hidden_fields((string) $page-&gt;getBody());  \/\/ the csrf field, for one\n    $fields['email'] = $email;  \/\/ your form's own fields go here\n    $fields['h-captcha-response'] = $solved['token'];\n    $fields['g-recaptcha-response'] = $solved['token'];  \/\/ the widget fills both\n    \/\/ Post to the form's action address; here that is the page itself.\n    return $site-&gt;post(PAGE_URL, [\n        'form_params' =&gt; $fields,\n        'headers' =&gt; ['Referer' =&gt; PAGE_URL],\n    ])-&gt;getStatusCode();\n}<\/pre>\n<\/div>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Step 4: sign up with retries, then run it<\/h2>\n<p>The sign_up function takes the time first. If PHP has a limit and set_time_limit exists, it restarts the clock with BUDGET plus 30 seconds, room for the SDK&#8217;s last sleep and the form post. On the command line, where the limit is 0, it changes nothing. A later attempt starts only if 10 seconds of the budget are left. The last block picks the exit: 2 for out of time, 1 for any other failure, plus a 504 or 502 status for a web page. It catches CapSkipError and RuntimeException side by side, because the SDK&#8217;s exceptions all extend CapSkipError, which is not a RuntimeException.<\/p>\n<p>Some hosts disable set_time_limit, and then the fatal error is back. With a 30 second limit and BUDGET left at 90, it came about 33 seconds in, inside the SDK&#8217;s sleep after its poll at about 28 seconds. A BUDGET of 29 failed the same way, while 25 ended with the TimeoutException at about 28 seconds. Without the call, keep BUDGET at least 10 seconds under the limit.<\/p>\n<p>Only ERROR_CAPTCHA_UNSOLVABLE earns a new task. The docs name ERROR_RECAPTCHA_INVALID_SITEKEY and ERROR_PROXY_CONNECT_REFUSED separately because a resubmitted task would fail the same way, so those end the script. The SDK puts the reply text from CapSkip into the ApiException message, and the app source builds a JSON error as an object with status 0 and the code in request, so the code searches the message with str_contains. When the site refuses a post, the loop asks for a fresh token, since a token works once. A status below 400 only means the site did not refuse the request, so also check for text that only a success shows.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">function sign_up(CapSkip $solver, string $email): int\n{\n    $deadline = microtime(true) + BUDGET;\n    \/\/ A limit of 0 means none, as on the command line. Otherwise restart PHP's\n    \/\/ clock with room to spare, so the SDK's TimeoutException fires first, not\n    \/\/ PHP's fatal error. Some hosts disable set_time_limit; then keep BUDGET\n    \/\/ at least 10 seconds under the limit instead.\n    if ((int) ini_get('max_execution_time') !== 0 &amp;&amp; function_exists('set_time_limit')) {\n        set_time_limit(BUDGET + 30);\n    }\n    for ($attempt = 1; $attempt &lt;= 3; $attempt++) {\n        try {\n            $solved = solve($solver, $deadline);\n        } catch (ApiException $e) {\n            if (!str_contains($e-&gt;getMessage(), 'ERROR_CAPTCHA_UNSOLVABLE')) {\n                throw $e;  \/\/ a refused sitekey or an unreachable proxy would fail again\n            }\n            error_log(&quot;attempt $attempt: ERROR_CAPTCHA_UNSOLVABLE, new task&quot;);\n            continue;\n        }\n        $status = post_form($solved, $email);\n        if ($status &lt; 400) {\n            return $status;\n        }\n        error_log(&quot;attempt $attempt: the site answered $status, new token&quot;);\n    }\n    throw new RuntimeException('no accepted form after 3 attempts');\n}<\/pre>\n<\/div>\n<div data-no-translation>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">try {\n    $status = sign_up($solver, 'you@example.com');\n    echo &quot;the site answered $status\\n&quot;;\n} catch (TimeoutException $e) {\n    if (!headers_sent()) {\n        http_response_code(504);  \/\/ no effect on the command line\n    }\n    echo 'out of time: ', $e-&gt;getMessage(), &quot;\\n&quot;;\n    exit(2);\n} catch (CapSkipError | RuntimeException $e) {\n    if (!headers_sent()) {\n        http_response_code(502);\n    }\n    echo get_class($e), ': ', $e-&gt;getMessage(), &quot;\\n&quot;;\n    exit(1);\n}<\/pre>\n<\/div>\n<div data-no-translation>\n<pre data-enlighter-language=\"bash\" class=\"EnlighterJSRAW\"># From the same PowerShell prompt, in the folder that holds the file\nphp hcaptcha_form.php<\/pre>\n<\/div>\n<p>Here is how the file behaved against the mock. The first five rows ran on PHP 8.0.30, 8.4.15 and 8.5.0 with Guzzle 8, and the web server rows also on 8.4.15 with Guzzle 7. The rest ran on all six versions with both Guzzle versions.<\/p>\n<table>\n<thead>\n<tr>\n<th>Mock setting<\/th>\n<th>What the script did<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Solve takes 12 seconds, command line<\/td>\n<td>Polls at 0, 0.3, 0.8, 1.8, 3.8, 7.8 and 12.8 seconds, then the form was accepted with status 200 after about 13 seconds<\/td>\n<\/tr>\n<tr>\n<td>Solve takes 38 seconds, built-in web server, 30 second limit<\/td>\n<td>Status 200 after about 43 seconds, the last poll at 42.9<\/td>\n<\/tr>\n<tr>\n<td>The same, with the set_time_limit call deleted<\/td>\n<td>PHP&#8217;s fatal error after about 33 seconds. The page body was PHP&#8217;s error text, and the last poll had gone out at about 28 seconds<\/td>\n<\/tr>\n<tr>\n<td>The same as the second row, with the call deleted and BUDGET set to 25<\/td>\n<td>Status 504 and the text out of time: timeout 24 exceeded, after about 28 seconds<\/td>\n<\/tr>\n<tr>\n<td>A task that never finishes, BUDGET 25, command line<\/td>\n<td>TimeoutException, exit code 2 and the message timeout 24 exceeded after about 28 seconds, with the last poll at 22.9<\/td>\n<\/tr>\n<tr>\n<td>First two solves refused<\/td>\n<td>The third task passed, after two lines in error_log<\/td>\n<\/tr>\n<tr>\n<td>Every solve refused<\/td>\n<td>Three attempt lines, then a RuntimeException after three tasks, with no request to the site<\/td>\n<\/tr>\n<tr>\n<td>The first post answered with 403<\/td>\n<td>A second token was requested and that post was accepted<\/td>\n<\/tr>\n<tr>\n<td>Empty sitekey, or a page address that is not absolute<\/td>\n<td>A ValidationException at once. The mock saw no task, and the site was never contacted<\/td>\n<\/tr>\n<tr>\n<td>ERROR_PROXY_CONNECT_REFUSED on the poll<\/td>\n<td>The script stopped after its first task and retried nothing<\/td>\n<\/tr>\n<tr>\n<td>Nothing listening on the CapSkip port<\/td>\n<td>A NetworkException after about 2 seconds<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Common errors when you solve hCaptcha in PHP<\/h2>\n<p>The 400 and 403 verdicts are the rules of my mock. The account errors come from reading the CapSkip app source, and I did not run them.<\/p>\n<table>\n<thead>\n<tr>\n<th>What you see<\/th>\n<th>Cause<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Fatal error: Maximum execution time of 30 seconds exceeded<\/td>\n<td>PHP&#8217;s limit ran out inside the SDK&#8217;s wait. The set_time_limit call is missing, or the host disabled that function<\/td>\n<td>Keep the call in sign_up. If the host disabled it, set BUDGET at least 10 seconds under the limit<\/td>\n<\/tr>\n<tr>\n<td>out of time: timeout 89 exceeded (HTTP 504, exit code 2)<\/td>\n<td>A TimeoutException: no token arrived within the timeout. CapSkip had not finished, or the task was still waiting for a free thread<\/td>\n<td>Look at the task in the CapSkip Monitor. Raise BUDGET only if every timeout in front of PHP allows it<\/td>\n<\/tr>\n<tr>\n<td>ValidationException<\/td>\n<td>The SDK stopped the call before any request left PHP: a blank sitekey, a relative or non-http page address, an invisible value outside 0, 1, true and false, or an unknown option such as domain. The message says which<\/td>\n<td>Fix the argument that the message names<\/td>\n<\/tr>\n<tr>\n<td>ApiException whose message holds ERROR_CAPTCHA_UNSOLVABLE<\/td>\n<td>The widget was not passed<\/td>\n<td>Submit a new task, which sign_up does up to three times<\/td>\n<\/tr>\n<tr>\n<td>ApiException with ERROR_RECAPTCHA_INVALID_SITEKEY<\/td>\n<td>hCaptcha did not accept that sitekey for that page, per the docs<\/td>\n<td>Recopy data-sitekey and confirm that PAGE_URL is the page showing the widget<\/td>\n<\/tr>\n<tr>\n<td>ApiException with ERROR_PROXY_CONNECT_REFUSED<\/td>\n<td>CapSkip cannot connect to the proxy named in the proxy option<\/td>\n<td>Check the proxy address and type, or leave the proxy option out<\/td>\n<\/tr>\n<tr>\n<td>ApiException with ERROR_WRONG_USER_KEY or ERROR_KEY_DOES_NOT_EXIST<\/td>\n<td>CapSkip is checking keys, and the &quot;apiKey&quot; key is missing or wrong<\/td>\n<td>Pass the key that CapSkip expects as the &quot;apiKey&quot; key of the constructor array<\/td>\n<\/tr>\n<tr>\n<td>ApiException with ERROR_NO_SLOT_AVAILABLE, ERROR_ZERO_BALANCE or ERROR_IP_NOT_ALLOWED<\/td>\n<td>Account errors from the key checks in CapSkip: the key is over its request rate limit, has no credits left for this method, or is bound to a device with another IP address<\/td>\n<td>Check the key&#8217;s settings in CapSkip. For the rate limit, wait a few seconds and run the script again<\/td>\n<\/tr>\n<tr>\n<td>NetworkException: Failed to connect to 127.0.0.1 port 8080<\/td>\n<td>No server answers at the host and port in the constructor array<\/td>\n<td>Start CapSkip, then compare its connection settings with the array. A script on another machine needs Server mode<\/td>\n<\/tr>\n<tr>\n<td>Deprecated: Function curl_close() is deprecated<\/td>\n<td>PHP 8.5 deprecates curl_close, and the SDK&#8217;s Http.php still calls it after each request to CapSkip. The solve works, but with display_errors on the notice starts the output, so a web page can no longer get its 504 or 502 status<\/td>\n<td>Switch E_DEPRECATED off in error_reporting, or display_errors off, until the SDK drops curl_close<\/td>\n<\/tr>\n<tr>\n<td>cURL error 60: SSL certificate problem<\/td>\n<td>PHP for Windows ships with curl.cainfo unset (it was empty on all six builds here), so Guzzle fails on an https site. The SDK&#8217;s own requests go to CapSkip over http and are not affected<\/td>\n<td>Download a cacert.pem file, for example from curl.se, and set curl.cainfo to its path in php.ini<\/td>\n<\/tr>\n<tr>\n<td>400 from the site, no session cookie<\/td>\n<td>The post went out without the cookie the page set<\/td>\n<td>Load the page and post through one client with one CookieJar<\/td>\n<\/tr>\n<tr>\n<td>403 from the site with a fresh token<\/td>\n<td>The post carried Guzzle&#8217;s own User-Agent, or the token had been used before or was about two minutes old<\/td>\n<td>Send the &quot;userAgent&quot; entry from the same result, once per token, right after the solve<\/td>\n<\/tr>\n<tr>\n<td>403 from a site that wants a Referer<\/td>\n<td>Guzzle sends none<\/td>\n<td>Keep the Referer line in post_form<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Reaching a CapSkip server from your PHP script<\/h2>\n<p>Moving CapSkip off the PC that runs PHP means changing the host and port in the constructor array. Server mode lets other devices reach CapSkip on your network or public IP, and the setup guide recommends a static one. Server mode starts with the port open to every address. To keep it to the machines you expect, add a Windows Firewall block rule for the others. The solver stays on your hardware and nothing is metered.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">FAQ<\/h2>\n<details style=\"border:1px solid #e2e5ee;border-radius:10px;padding:14px 18px;margin:0 0 12px;\">\n<summary style=\"cursor:pointer;\">\n<h3 style=\"font-size:1.15rem;line-height:1.4;display:inline;margin:0;\">Does the same hcaptcha() call handle invisible and Enterprise widgets?<\/h3>\n<\/summary>\n<p style=\"margin:12px 0 0;\">Yes. The SDK and the API docs treat both as the same method with an extra field: invisible set to 1 for an invisible widget, and the rqdata value in data for an Enterprise site, requested anew for every task. Put either in task_options. Against the mock both reached in.php, and a retry sent a new data value. I could not test a real Enterprise site.<\/p>\n<\/details>\n<details style=\"border:1px solid #e2e5ee;border-radius:10px;padding:14px 18px;margin:0 0 12px;\">\n<summary style=\"cursor:pointer;\">\n<h3 style=\"font-size:1.15rem;line-height:1.4;display:inline;margin:0;\">Should hCaptcha in PHP run in a web request or on the command line?<\/h3>\n<\/summary>\n<p style=\"margin:12px 0 0;\">The command line is simpler. PHP has no limit there, so BUDGET is the only clock, and Windows Task Scheduler can start the file on a timer. With a visitor waiting, let the page start the job and a command line worker do the waiting.<\/p>\n<\/details>\n<details style=\"border:1px solid #e2e5ee;border-radius:10px;padding:14px 18px;margin:0 0 12px;\">\n<summary style=\"cursor:pointer;\">\n<h3 style=\"font-size:1.15rem;line-height:1.4;display:inline;margin:0;\">Does solving hCaptcha in PHP need a proxy?<\/h3>\n<\/summary>\n<p style=\"margin:12px 0 0;\">Not for a test. The docs say CapSkip does not force a proxy for hCaptcha, but a steady stream of solves from one IP is what its rate limits are built to catch. For volume, give CapSkip a proxy list in its settings or pass the proxy option, a string such as login:password@IP:PORT. It reached the mock as proxy and proxytype. Submit the form from the same address with Guzzle&#8217;s proxy option. I tested no real proxy.<\/p>\n<\/details>\n<p>Solving hCaptcha in PHP means one hcaptcha() call with a timeout you set, a set_time_limit call at the top of the job, and a BUDGET under every other timeout. Retry only what CapSkip couldn&#8217;t solve, and post under the User-Agent that came with the token. Because CapSkip is an <a href=\"https:\/\/capskip.com\/\">unlimited captcha solver<\/a> on a flat license, a refused token costs only another pass through the loop. For the other CAPTCHA types, the <a href=\"https:\/\/capskip.com\/php-captcha-solver\/\">PHP CAPTCHA solver page<\/a> lists the SDK calls. The <a href=\"https:\/\/capskip.com\/captcha-demo\/hcaptcha\/\">hCaptcha demo<\/a> shows a widget being passed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A PHP script that waits for an hCaptcha token runs into max_execution_time. Here is the SDK call with its own timeout and the Guzzle code that posts the form under the right User-Agent.<\/p>","protected":false},"author":1,"featured_media":27322,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"hCaptcha in PHP: SDK Call, Time Limit, Form Post | CapSkip","rank_math_description":"Solve hCaptcha in PHP with the CapSkip SDK: set a timeout inside max_execution_time, then post the form with Guzzle under the right User-Agent.","rank_math_focus_keyword":"hcaptcha in php","footnotes":""},"categories":[70],"tags":[],"class_list":["post-27323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-captcha"],"_links":{"self":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts\/27323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/comments?post=27323"}],"version-history":[{"count":1,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts\/27323\/revisions"}],"predecessor-version":[{"id":27324,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts\/27323\/revisions\/27324"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/media\/27322"}],"wp:attachment":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/media?parent=27323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/categories?post=27323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/tags?post=27323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}