Title: Get JavaScript-rendered HTML in PHP — working code
Open Graph Title: Get JavaScript-rendered HTML in PHP — working code
X Title: Get JavaScript-rendered HTML in PHP — working code
Description: Fetch the HTML of a JavaScript page after it rendered, in PHP: sync, async with a webhook, and error handling. Tested code.
Open Graph Description: Fetch the HTML of a JavaScript page after it rendered, in PHP: sync, async with a webhook, and error handling. Tested code.
X Description: Fetch the HTML of a JavaScript page after it rendered, in PHP: sync, async with a webhook, and error handling. Tested code.
Mail addresses
contact@urlpipe.dev
Opengraph URL: https://urlpipe.dev/code/php/rendered-html
Domain: urlpipe.dev
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://urlpipe.dev/#organization","name":"URLpipe","url":"https://urlpipe.dev","logo":"https://urlpipe.dev/icon.png","sameAs":["https://github.com/URLpipe"],"founder":{"@type":"Person","name":"Roger Campos","url":"https://rogercampos.com"}},{"@type":"WebSite","@id":"https://urlpipe.dev/#website","url":"https://urlpipe.dev","name":"URLpipe","publisher":{"@id":"https://urlpipe.dev/#organization"}}]}
{"@context":"https://schema.org","@graph":[{"@type":"TechArticle","@id":"https://urlpipe.dev/code/php/rendered-html#article","headline":"Get JavaScript-rendered HTML in PHP — working code","description":"Fetch the HTML of a JavaScript page after it rendered, in PHP: sync, async with a webhook, and error handling. Tested code.","url":"https://urlpipe.dev/code/php/rendered-html","mainEntityOfPage":"https://urlpipe.dev/code/php/rendered-html","datePublished":"2026-09-24","dateModified":"2026-09-24","author":{"@type":"Person","name":"Roger Campos","url":"https://rogercampos.com"},"publisher":{"@id":"https://urlpipe.dev/#organization"},"image":"https://urlpipe.dev/og-image.png"},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"How is this different from fetching the URL myself?","acceptedAnswer":{"@type":"Answer","text":"A plain GET returns what the server sent before any JavaScript ran. /html returns the DOM after the page's scripts ran in real Chrome — the HTML a visitor's browser actually holds."}},{"@type":"Question","name":"Can I wait for content that loads late?","acceptedAnswer":{"@type":"Answer","text":"Yes: page_options.wait_for_selector waits up to 10 seconds for an element to appear, and delay adds a fixed wait. If the element never appears the request is a 422 and costs nothing."}},{"@type":"Question","name":"Does URLpipe follow robots.txt?","acceptedAnswer":{"@type":"Answer","text":"Yes, by default, for every project. You can turn it off per project, and then you are responsible for having the right to fetch those pages."}},{"@type":"Question","name":"Do I need an SDK to call URLpipe from PHP?","acceptedAnswer":{"@type":"Answer","text":"No Composer package: the curl extension is part of PHP, and the API is one POST per job."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://urlpipe.dev/"},{"@type":"ListItem","position":2,"name":"Code recipes","item":"https://urlpipe.dev/code"},{"@type":"ListItem","position":3,"name":"PHP","item":"https://urlpipe.dev/code/php"},{"@type":"ListItem","position":4,"name":"Get the rendered HTML of a JavaScript page in PHP","item":"https://urlpipe.dev/code/php/rendered-html"}]},{"@type":"HowTo","name":"Get the rendered HTML of a JavaScript page in PHP","description":"To get the HTML of a JavaScript-rendered page in PHP, POST its URL to https://urlpipe.dev/html with sync set to true. The body is the DOM after the page's scripts ran in real Chrome, serialized as HTML — what a visitor's browser holds, not what the server first sent — read with curl_exec with CURLOPT_RETURNTRANSFER, for 1 credit.","url":"https://urlpipe.dev/code/php/rendered-html","tool":[{"@type":"HowToTool","name":"PHP 8.1+"}],"step":[{"@type":"HowToStep","name":"Before you start","text":"Nothing to install beyond PHP itself: the curl extension ships with it. Check it is loaded, and put your API key in the environment.","url":"https://urlpipe.dev/code/php/rendered-html#setup"},{"@type":"HowToStep","name":"Save the rendered HTML and report its size","text":"Without CURLOPT_RETURNTRANSFER, curl_exec() prints the body and returns true — the most common reason a PHP example "returns nothing". curl_exec() returns false only when there was no HTTP answer at all; a 422 is still a string, so read the status too. strlen() counts bytes, not characters, which is the size you want here.","url":"https://urlpipe.dev/code/php/rendered-html#sync"},{"@type":"HowToStep","name":"The async variant: a token, a webhook and a poll","text":"Leave out sync and the answer is a token, straight away. send() uses CURLOPT_CUSTOMREQUEST so one function makes both the POST and the GETs, and array destructuring ([$status, $body] = …) keeps the loop short.","url":"https://urlpipe.dev/code/php/rendered-html#async"},{"@type":"HowToStep","name":"Handle errors and retries","text":"json_decode() returns null for a body that is not JSON (a proxy or load balancer in front of the API can answer in HTML), and ?: [] turns that into an empty array. CURLOPT_HEADERFUNCTION is how curl hands you response headers one line at a time.","url":"https://urlpipe.dev/code/php/rendered-html#errors"}]}]}
| view-transition | same-origin |
| csrf-param | authenticity_token |
| csrf-token | v2jqwCnjZXSpYNUKfs8-q38zxwGWt8Zf3R4q0ix7xXnHNJWYZhYiNj6DLoc-dDy0RlLRwwpJKmMMhORu5QcNMA |
| csp-nonce | 2e32b76918bf4ccf429c9965fcc6f7ce |
| og:type | website |
| og:site_name | URLpipe |
| og:locale | en_US |
| og:image | https://urlpipe.dev/og-image.png |
| og:image:width | 1200 |
| og:image:height | 630 |
| og:image:alt | URLpipe — URL in. Clean data out. |
| twitter:card | summary_large_image |
| twitter:image | https://urlpipe.dev/og-image.png |
| twitter:image:alt | URLpipe — URL in. Clean data out. |
| theme-color | #3b82f6 |
Links:
Viewport: width=device-width,initial-scale=1