开发者

Problems of using curl on windows compared to mac

开发者 https://www.devze.com 2023-01-31 09:05 出处:网络
i use xampp apache to run some of my php files. In one of my php file i use curl to get data from external website, on my windows machine, everything works fine. However, on my mac machine, my brows

i use xampp apache to run some of my php files.

In one of my php file i use curl to get data from external website, on my windows machine, everything works fine. However, on my mac machine, my browser just can not run those开发者_运维问答 files.. it just takes very long to load, and in the end stop loading.

Attached is one of my php file:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
'http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);

print $contents;
?>

I am really desprate on why mac machine can not run these files? is there another way to go about doing this on a mac machine? THanks all for your help!

EDIT: [SOLVED] Thanks all for your help. Manage to solve it, due, to because i am connecting to the net using a proxy server...thus my script need to handle that.

Code used:

<?php
$aContext = array(
'http' => array(
'proxy' =>'tcp://xxxxx:xx',
'request_fulluri' => true,
),
);
$cxContext = stream_context_create($aContext);

$content = file_get_contents("http://www.example.com", False, $csContext);

print $content;
?>


use echo file_get_contents('http://www.example.com');


Do you have the CURL extension installed on your MAC machine. Check that by running a php script with phpinfo(); in it and see if you have the CURL installed/enabled.

0

精彩评论

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