开发者

cURL not working correct!

I have a question about cURL. I am using cURL with this function:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Only this was causing an error: "Message: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set"

So I asked my hosting provider to fix this, and they did. But, and this is really stupid, they put a "curl" file in my bin directory. And I have no idea how to include this in my php script :S.

Never done it before, but can anybody help me. I am really stuck. I hope I posted enough info!

Tnx in advanced!


Tnx for all the great replies. But How would I fit "exec()" in this code?

    // create a new cURL resource
    $ch = curl_init();

    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_TRANSFERTEXT, TRUE);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_URL, $articleUrl);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 5);

    // grab URL and pass it to $grabArticle
    $grabArticle = curl_exec($ch);

Edit 2: Oké, I almost got it working :). It is working just fine when I run it in putty, but in my php script nothing happens :(

I run this:

$grabArticle = exec('/home/twittern/bin/curl -L -m 30 -w url_effective --max-redirs 5 http://fok.nl/4开发者_运维问答15758');
echo $grabArticle;

Any thing I am doing wrong?


Instead of using the built-in cURL functions within PHP, they are asking you to use the external command-line version.

Use the PHP exec() function to call the program, the command line options can be found on the curl man page.

Given that you probably need the response in full, you may need to use passthru() with output buffering or save the output to a (temporary) file.


PHP curl doesn't rely on a curl bin being available. (PHP supports curl by default since 4.0.2)

Your hosting provider just needs to make sure your PHP ini has safe_mode switched off.

But given the way the handled this (giving you a curl binary) it looks like you should use exec() to call it.

Personally, I'd recommend you find a better host.


Your provider sucks. Call them back and make them recompile php to include curl support.

Otherwise you are stuck with calling curl directly.

$result = exec("/bin/curl http://www.foobar.com");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜