Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php cURL silent option?

Tags:

php

curl

I was using curl from shell scripts and was setting -s option to make to make it silent How to set this option in php curl?

like image 451
Vamsi Krishna B Avatar asked Aug 17 '10 17:08

Vamsi Krishna B


4 Answers

http://php.net/manual/en/ref.curl.php

In recent versions of php, CURLOPT_MUTE has (probably) been deprecated. Any attempt of using curl_setopt() to set CURLOPT_MUTE will give you a warning like this:

PHP Notice: Use of undefined constant CURLOPT_MUTE - assumed 'CURLOPT_MUTE' in ....

If you wish to silence the curl output, use the following instead:

<?php
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
?>

And then,

<?php
    $curl_output=curl_exec($ch);
?>

The output of the curl operation will be stored as a string in $curl_output while the operation remains totally silent.

like image 94
StuFF mc Avatar answered Oct 23 '22 18:10

StuFF mc


You want to set the CURLOPT_MUTE setting when initializing the connection:

curl_setopt($curl_resource, CURLOPT_MUTE, 1);
like image 20
jrtashjian Avatar answered Oct 23 '22 18:10

jrtashjian


This post is pretty old, but for future people looking for this answer, you need to use these two options in the current version of php5-curl:

<?php
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, false);
?>

The first option returns the raw response from curl_exec() so it can be assigned to a variable. The second option prevents curl_exec() from printing the response.

like image 43
Jay Sudo Avatar answered Oct 23 '22 18:10

Jay Sudo


Looks like CURLOPT_MUTE has been deprecated in recent versions of php.

I'm using PHP 5.3.6 and I'm getting Use of undefined constant CURL_MUTE - assumed 'CURL_MUTE' whenever I try to set this option.

like image 3
el.atomo Avatar answered Oct 23 '22 18:10

el.atomo