Question

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.

Was it helpful?

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.

OTHER TIPS

I read now and then on forums and chats that allow_url_fopen has to be enabled for Joomla to work properly. That's an "urban legend", leftover from old versions, but almost no one seems to actually test and confirm that fact. It seems the Docs are also wrong about it.

Joomla! CMS & Framework don't depend on "allow_url_fopen" being enabled. Period!

Quite the contrary, J! Framework has a very good and robust core subpackage HTTP, which supports "drivers" based on cURL, streams and sockets. Which means even with fopen() URL wrappers ("streams" driver) disabled altogether ("allow_url_fopen = 0"), any extensions implementing HTTP subpackage still has "cURL" and "sockets" driver available. For example, Joomla Update component will, in case "allow_url_fopen" is disabled, fall back on using cURL wrapper (given cURL PHP extension is enabled).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top