11.8 Getting Information Regarding a cURL Transfer


For some reason your cURL transfers aren't succeeding.

Technique

Set the $progress , $mute , and $verbose properties in the Net_Curl class:

 <?php //Initialize the CURL transfer $conn = new Net_Curl('http://www.webtechniques.com/'); if (Net_Curl::isError($conn)) {     die(sprintf('Error [%d]: %s',                 $conn->getCode(), $conn->getMessage())); } // Set transfer options $conn->verbose = 1; $conn->progress = 1; $conn->mute = 0; // Execute the transfer $data = $conn->execute(); if (Net_Curl::isError($data)) {     die(sprintf('Error [%d]: %s',                 $data->getCode(), $data->getMessage())); } print "The Results of your transfer were:\n<br>\n"; print $data; ?> 

Comments

Setting the verbose and progress properties to nonfalse values tells PHP to report all its actions to STDERR (the standard error stream). Setting the mute property to tells PHP not to suppress any warnings or errors.

If you want PHP to fail when a bad error code (< 300) is returned from a Web site, set the fail property to a nonfalse value:

 <?php $conn = new Net_Curl('http://www.mcp.com/index.cfm'); if (Net_Curl::isError($conn)) {     die(sprintf('Error [%d]: %s',                 $conn->getCode(), $conn->getMessage())); } $conn->fail = true; $data = $conn->execute(); if (Net_Curl::isError($data)) {     die(sprintf('Error [%d]: %s',                 $data->getCode(), $data->getMessage())); } print "The Results of your transfer were: \n<br>\n"; print $data; ?> 


PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net