Best practice for using fopen() or file_get_contents() to retrieve web pages

joomla, joomla1.5, php

Solution

They will both work without curl, but you need to have `allow_url_fopen` enabled. You can check that by executing phpinfo(). There are security implications however, see this:

Should I allow 'allow_url_fopen' in PHP?

So to grab pages, you can use `fopen(`), `file_get_contents()` or some other independent HTTP client implemented in PHP such as HttpClient that can function without those.

Problem

I am looking for some advice on the best way to retrieve information from a web page (my own site) and then search through that information to find a certain text. Keeping in mind that some of the servers that run PHP/Joomla do not have cURL enabled, I don't want to cause any unexpected errors. I've looked at both `fopen()` and `file_get_contents()` and both seem to have conflicting views of each other in terms of which will work with/without cURL.

Original source

Related problems