Note that there are some explanatory texts on larger screens.

plurals
  1. POSilence PHP cURL output in CLI
    primarykey
    data
    text
    <p>I am working on a scrapper (in PHP) and use cURL to fetch pages. The script can be run both in CLI &amp; browser. This is my first time working with PHP on CLI and I was trying to make the screen pretty and have a nice data representation like scrape statistics show up.</p> <p>I am able to generate the output the way I want it, well almost. But with every cURL request the server makes, it also outputs this the extra header information like this :</p> <pre><code>* About to connect() to imbd.com port 80 (#0) * Trying 123.111.222.333... * connected &gt; GET /categories/something.html HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20130401 Firefox/21.0 Host: imdb.com Accept: */* &lt; HTTP/1.1 200 OK &lt; Server: nginx/1.4.1 &lt; Date: Wed, 25 Dec 2013 02:17:06 GMT &lt; Content-Type: text/html &lt; Transfer-Encoding: chunked &lt; Connection: keep-alive &lt; Vary: Accept-Encoding &lt; X-Powered-By: PHP/5.3.17 &lt; Set-Cookie: mobileType=0%something; expires=Wed, 01-Jan-2014 02:17:06 GMT; path=/; domain=.imdb.com &lt; * Connection #0 to host imdb.com left intact * Closing connection #0 ... Statistics ... </code></pre> <p>Function that uses cURL</p> <pre><code> public function getHTML($url) { $user_agent = "Mozilla/5.0 (Windows NT 5.1; U; zh-cn; rv:1.9.1.6) ..."; $options = Array( CURLOPT_RETURNTRANSFER =&gt; TRUE, CURLOPT_FOLLOWLOCATION =&gt; TRUE, CURLOPT_AUTOREFERER =&gt; TRUE, CURLOPT_CONNECTTIMEOUT =&gt; 120, CURLOPT_TIMEOUT =&gt; 120, CURLOPT_MAXREDIRS =&gt; 10, CURLOPT_USERAGENT =&gt; $user_agent, CURLOPT_URL =&gt; $url, CURLOPT_VERBOSE =&gt; true, CURLOPT_SSL_VERIFYPEER =&gt; false, ); $ch = curl_init(); curl_setopt_array($ch, $options); $data = curl_exec($ch); curl_close($ch); return $data; } </code></pre> <p>Now all I want to do is <strong>hide this information from the CLI</strong> as it does in the browser. Had it been cli curl, i would use <code>-s</code> to shut it up. But I am unable to find an PHP alternative for this. Also, <code>CURLOPT_MUTE</code> is depreciated. All Google gave me was to set <code>CURLOPT_RETURNTRANSFER</code> true, which I already have.</p> <p>Also I would like to know how can I <strong>avoid setting any cookies</strong> to avoid tracking.</p> <p>If it helps in any way I am using</p> <ul> <li>OS : Ubuntu</li> <li>Software : PHP5.5</li> <li>Framework : CodeIgniter 3.0-dev</li> <li>Extension: cURL</li> <li>Interface : Command Line (Terminal)</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload