开发者

Any alternative to curl_exec()?

开发者 https://www.devze.com 2023-04-02 09:39 出处:网络
I am trying to make a sort of license checking script, but as not all hosts allow curl_exec, I would like to know, if there is any alternative way of making a call-back?

I am trying to make a sort of license checking script, but as not all hosts allow curl_exec, I would like to know, if there is any alternative way of making a call-back?

This is how I do it with curl:

curl_setopt($ch, CURLOPT_URL, $url."/my_script.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $info);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_ex开发者_运维问答ec($ch);


You can simply use file_get_contents() with URLs:

file_get_contents('http://www.google.com');

This may be disabled, though, with just a simple INI option allow_url_fopen.

Alternatively, you may use fsockopen(), which should be available on most systems.

With fsockopen() you can open a socket to a HTTP server, then communicate using standard fwrite() and fread(). The downside is that you must write HTTP request headers by yourself, and you must also parse HTTP response headers too. If you look at fsockopen() on PHP's manual, you can see plenty of examples: http://fr2.php.net/fsockopen

My suggestion is to use cURL as primary option, file_get_contents() as secondary (if ini_get('allow_url_fopen') returns a positive result) and implement solutions likefsockopen() as fallback.


You could switch curl_multi_exec, but that's probably disabled as well.

Alternatively, use the HTTP stream wrapper. To configure a POST request, you'll need to set up your own HTTP context.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号