Search code examples
phpsimple-html-dom

Set timeout in simple_html_dom


Can i set timeout for file_get_html() in simple_html_dom?

I need that this call wait for 5 sec. to render all scripts in a page.

Or another way to do this in PHP, parsing html pages using css selectors?


Solution

  • You can not do that with simple_html_dom() or file_get_contents() or any other 'pure' PHP.

    For this purpose you have to use technologies like PhantomJS. Load the page into PhantomJS, wait for JavaScript to finish executing, then use the HTML that has been generated.

    PHP PhantomJS should make that quite simple (see the "Delay page render" example in the Documentation).