I’m writing an extension that pulls some data to an external site.
I’d wish to know what’s the more reliable way to do that.
At the moment I’m using cURL, but since some hosting doesn’t have that library installed, I’m using this method as fallback (fopen with stream_context_create).
However, sometimes it fails anyway, and I can’t reproduce the error.
Do you know any other method? Is there room for improvement?
EDIT:
sadly no, I have no log since i have no problems on my tests. some customers are reporting that data is not sent, and I was wondering if there are a set of fallback actions, starting from the most common one (ie cURL) to a “last resort” one.
If you look hard enough, there probably are more options than the two you mentioned, but at some point the customer needs to have a decent host and not put the blame on you.
cURL
Most hosts provide cURL. Some will disable it, but it’s easy to check for that.
fopen(url)
This can be disabled by the allow_url_fopen runtime option, which is also easy to check for.
You could get really creative and use external Perl scripts, for example, to do the work PHP cannot (per config), but what if the host has the external execution functions disabled?
I think it is sufficient to offer these two options, and then provide proper error handling so the customer knows it isn’t going to work. It isn’t a fair expectation for your script to run on every host. Just don’t leave the customer seeing something didn’t work and you didn’t get them enough information to know it’s their host’s fault.