home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / Net / Curl.php < prev    next >
Encoding:
PHP Script  |  2005-09-26  |  21.5 KB  |  800 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  4.  
  5. /**
  6.  * Net_Curl
  7.  *
  8.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  9.  * that is available through the world-wide-web at the following URI:
  10.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  11.  * the PHP License and are unable to obtain it through the web, please
  12.  * send a note to license@php.net so we can mail you a copy immediately.
  13.  *
  14.  * @category   Net
  15.  * @package    Net_Curl
  16.  * @author     David Costa <gurugeek@php.net>
  17.  * @author     Sterling Hughes <sterling@php.net>                           
  18.  * @author     Joe Stump <joe@joestump.net> 
  19.  * @copyright  1997-2005 The PHP Group
  20.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  21.  * @version    CVS: $Revision: 1.11 $
  22.  * @link       http://pear.php.net/package/Net_Curl
  23.  */
  24.  
  25. require_once('PEAR.php');
  26.  
  27. class Net_Curl 
  28. {
  29.     // {{{ Public Properties
  30.     /**
  31.      * The URL for cURL to work with
  32.      *
  33.      * @var string $url
  34.      * @access public
  35.      */
  36.     var $url;
  37.   
  38.     /**
  39.      * The Username for standard HTTP Authentication
  40.      *
  41.      * @var string $username
  42.      * @access public
  43.      */
  44.     var $username = '';
  45.     
  46.     /**
  47.      * The Password for standard HTTP Authentication
  48.      *
  49.      * @var string $password
  50.      * @access public
  51.      */
  52.     var $password = ''; 
  53.     
  54.     /**
  55.      * The SSL version for the transfer
  56.      *
  57.      * @var integer $sslVersion
  58.      * @access public
  59.      */
  60.     var $sslVersion;
  61.     
  62.     /**
  63.      * The filename of the SSL certificate
  64.      *
  65.      * @var string $sslCert
  66.      * @access public
  67.      */
  68.     var $sslCert;
  69.     
  70.     /**
  71.      * The password corresponding to the certificate
  72.      * in the $sslCert property
  73.      *
  74.      * @var string $sslCertPasswd
  75.      * @access public
  76.      */
  77.     var $sslCertPasswd;
  78.   
  79.     /**
  80.      * User Agent string when making an HTTP request
  81.      *
  82.      * @var string $userAgent
  83.      * @access public
  84.      */
  85.     var $userAgent;
  86.     
  87.     /**
  88.      * Whether or not to include the header in the results
  89.      * of the CURL transfer
  90.      *
  91.      * @var boolean $header
  92.      */
  93.     var $header = false;
  94.     
  95.     /**
  96.      * Whether or not to output debug information while executing a
  97.      * curl transfer
  98.      *
  99.      * @var boolean $verbose
  100.      * @access public
  101.      */
  102.     var $verbose = false;
  103.     
  104.     /**
  105.      * Whether or not to display a progress meter for the current transfer
  106.      *
  107.      * @var boolean $progress
  108.      * @access public
  109.      */
  110.     var $progress = false;
  111.     
  112.     /**
  113.      * Whether or not to suppress error messages
  114.      *
  115.      * @var boolean $mute
  116.      * @access public
  117.      */
  118.     var $mute = false;
  119.     
  120.     /**
  121.      * Whether or not to follow HTTP Location headers.
  122.      *
  123.      * @var boolean $followLocation
  124.      * @access public
  125.      */
  126.     var $followLocation = true;
  127.  
  128.     /**
  129.      * Whether or not to follow HTTP Location headers.
  130.      * 
  131.      * @var boolean $follow_location
  132.      * @access public
  133.      * @deprecated
  134.      */
  135.     var $follow_location = false;
  136.   
  137.     /**
  138.      * Time allowed for current transfer, in seconds.  0 means no limit
  139.      *
  140.      * @var int $timeout
  141.      * @access public
  142.      */
  143.     var $timeout = 0;
  144.   
  145.     /**
  146.      * Whether or not to return the results of the
  147.      * current transfer
  148.      *
  149.      * @var boolean $returnTransfer
  150.      * @access public
  151.      */
  152.     var $returnTransfer = true;
  153.  
  154.     /**
  155.      * Whether or not to return the results of the
  156.      * current transfer
  157.      *
  158.      * @var boolean $return_transfer
  159.      * @access public
  160.      * @deprecated
  161.      */
  162.     var $return_transfer = false;
  163.     
  164.     /**
  165.      * The type of transfer to perform (ie. 'POST', 'GET', 'PUT', etc)
  166.      *
  167.      * @var string $type
  168.      * @access public
  169.      */
  170.     var $type;
  171.     
  172.     /**
  173.      * The file to upload
  174.      *
  175.      * @var string $file
  176.      * @access public
  177.      */
  178.     var $file;
  179.     
  180.     /**
  181.      * The file size of the file pointed to by the $file
  182.      * property
  183.      *
  184.      * @var integer $fileSize
  185.      * @access public
  186.      */
  187.     var $fileSize;
  188.  
  189.     /**
  190.      * The file size of the file pointed to by the $file
  191.      * property
  192.      *
  193.      * @var integer $file_size
  194.      * @access public
  195.      * @deprecated
  196.      */
  197.     var $file_size = false;
  198.  
  199.     
  200.     /**
  201.      * The cookies to send to the remote site
  202.      *
  203.      * @var array $cookies
  204.      * @access public
  205.      */
  206.     var $cookies = array();
  207.     
  208.     /**
  209.      * Additional HTTP headers to send to the remote site
  210.      *
  211.      * @var array $httpHeaders
  212.      * @access public
  213.      */
  214.     var $httpHeaders = null;
  215.  
  216.     /**
  217.      * Additional HTTP headers to send to the remote site
  218.      *
  219.      * @var array $http_headers
  220.      * @access public
  221.      * @deprecated
  222.      */
  223.     var $http_headers = false;
  224.     
  225.     /**
  226.      * The fields to send in a 'POST' request
  227.      *
  228.      * @var array $fields
  229.      * @access public
  230.      */
  231.     var $fields;
  232.     
  233.     /**
  234.      * The proxy server to go through
  235.      *
  236.      * @var string $proxy
  237.      * @access public
  238.      */
  239.     var $proxy;
  240.     
  241.     /**
  242.      * The username for the Proxy server
  243.      *
  244.      * @var string $proxyUser
  245.      * @access public
  246.      */
  247.     var $proxyUser;
  248.     
  249.     /**
  250.      * The password for the Proxy server
  251.      *
  252.      * @var string $proxyPassword
  253.      * @access public
  254.      */
  255.     var $proxyPassword;
  256.  
  257.     /**
  258.      * $verifyPeer
  259.      *
  260.      * FALSE to stop CURL from verifying the peer's certificate.
  261.      * Alternate certificates to verify against can be specified
  262.      * with the CURLOPT_CAINFO option or a certificate directory
  263.      * can be specified with the CURLOPT_CAPATH option.
  264.      * CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE
  265.      * if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2).
  266.      *
  267.      * @var boolean $verifyPeer
  268.      * @access public
  269.      */
  270.     var $verifyPeer = true;
  271.  
  272.     /**
  273.      * $verifyHost
  274.      *
  275.      * 0 : to stop CURL from verifying the host's certificate.
  276.      * 1 : to check the existence of a common name in the SSL peer certificate.
  277.      * 2 : to check the existence of a common name  and also verify that it 
  278.      *     matches the hostname provided.
  279.      *
  280.      * @var bool $verifyHost
  281.      * @access public
  282.      */
  283.     var $verifyHost = 2;
  284.  
  285.     /**
  286.      * $caInfo
  287.      *
  288.      * Set value for CURLOPT_CAINFO. The name of a file holding one or more 
  289.      * certificates to verify the peer with. This only makes sense when used 
  290.      * in combination with CURLOPT_SSL_VERIFYPEER. curl-ca-bundle.crt is 
  291.      * avaible on the Curl website http://curl.haxx.se/ for download inside 
  292.      * the packages.
  293.      *
  294.      * @var string $caInfo
  295.      * @access public
  296.      */
  297.     var $caInfo = '';
  298.  
  299.     /**
  300.      * $caPath
  301.      *
  302.      * Set value for CURLOPT_CAPATH. A directory that holds multiple CA 
  303.      * certificates. Use this option alongside CURLOPT_SSL_VERIFYPEER.
  304.      *
  305.      * @var string $caPath
  306.      * @access public
  307.      */
  308.     var $caPath;
  309.     // }}}
  310.     // {{{ Private Properties
  311.     /**
  312.      * The current curl handle
  313.      *
  314.      * @var resource $_ch
  315.      * @access private
  316.      * @see Net_Curl::create()
  317.      */
  318.     var $_ch = null;
  319.  
  320.     /**
  321.      * The file upload resource
  322.      *
  323.      * The CURLOPT_INFILE requires a file resource and not just a file name. 
  324.      * This is used by execute to open the file.
  325.      *
  326.      * @var resource $_fp
  327.      * @access private
  328.      * @see Net_Curl::execute()
  329.      */
  330.     var $_fp = null;
  331.     // }}}
  332.     // {{{ __construct($url = '', $userAgent = '')
  333.     /**
  334.      * The Net_Curl PHP 5.x constructor, called when a new Net_Curl object
  335.      * is initialized (also called via 4.x constructor)
  336.      *
  337.      * @param string $url The URL to fetch (can be set using the $url property as well)
  338.      * @param string $userAgent The userAgent string (can be set using the $userAgent property as well)
  339.      * @access public
  340.      * @author Joe Stump <joe@joestump.net> 
  341.      */
  342.     function __construct($url = '', $userAgent = '')
  343.     {
  344.         if (is_string($url) && strlen($url)) {
  345.             $this->url = $url;
  346.         }
  347.       
  348.         if (is_string($userAgent) && strlen($userAgent)) {
  349.             $this->userAgent = $userAgent;
  350.         }
  351.     }
  352.     // }}}
  353.     // {{{ Net_Curl($url = '', $userAgent = '')
  354.     /**
  355.      * Net_Curl
  356.      *
  357.      * PHP 4.x constructor.
  358.      *
  359.      * @access public
  360.      * @author Joe Stump <joe@joestump.net>
  361.      */
  362.     function Net_Curl($url = '', $userAgent = '')
  363.     {
  364.         $this->__construct($url,$userAgent);          
  365.     }
  366.     // }}}
  367.     // {{{ execute()
  368.     /**
  369.      * Executes a prepared CURL transfer
  370.      *
  371.      * Run this function to execute your cURL request. If all goes well you
  372.      * should get a string (the output from the remote host regarding your
  373.      * request) or true (if you choose to output directly to the browser). If
  374.      * something fails then PEAR_Error is returned.
  375.      *
  376.      * <code>
  377.      * <?php
  378.      *     require_once('Net/Curl.php');
  379.      *     
  380.      *     $curl = & new Net_Curl('http://www.example.com');
  381.      *     $curl->fields = array('foo' => '1', 'bar' => 'apple');
  382.      *     $result = $curl->execute();
  383.      *     if (!PEAR::isError($result)) {
  384.      *         echo $result;
  385.      *     }
  386.      * ?>
  387.      * </code>
  388.      *
  389.      * @access public
  390.      * @author Sterling Hughes <sterling@php.net>
  391.      * @author Joe Stump <joe@joestump.net> 
  392.      * @return PEAR_Error on failure, true/result on success
  393.      * @since  PHP 4.0.5
  394.      */
  395.     function execute()
  396.     {
  397.         // Create cURL handle if it hasn't already been created
  398.         if (!is_resource($this->_ch)) {
  399.             $result = $this->create();
  400.             if (PEAR::isError($result)) {
  401.                 return $result;
  402.             }
  403.         }
  404.  
  405.         // Map the deprecated variables and throw a bunch of errors
  406.         $this->_mapDeprecatedVariables();
  407.  
  408.         // Default return value is true.
  409.         $ret = true;
  410.  
  411.         // Basic stuff
  412.         $ret = curl_setopt($this->_ch, CURLOPT_URL,    $this->url);
  413.         $ret = curl_setopt($this->_ch, CURLOPT_HEADER, $this->header);
  414.       
  415.         // Whether or not to return the transfer contents
  416.         if ($this->returnTransfer === true) {
  417.             $ret = curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, true);
  418.         }
  419.       
  420.         // HTTP Authentication
  421.         if ($this->username != '') {
  422.             $ret = curl_setopt($this->_ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
  423.         }
  424.       
  425.         // SSL Checks
  426.         if (isset($this->sslVersion)) {
  427.             $ret = curl_setopt($this->_ch, CURLOPT_SSLVERSION, $this->sslVersion);
  428.         }
  429.       
  430.         if (isset($this->sslCert)) {
  431.             $ret = curl_setopt($this->_ch, CURLOPT_SSLCERT, $this->sslCert);
  432.         }
  433.       
  434.         if (isset($this->sslCertPasswd)) {
  435.             $ret = curl_setopt($this->_ch, CURLOPT_SSLCERTPASSWD, $this->sslCertPasswd);
  436.         }
  437.       
  438.         // Proxy Related checks
  439.         if (isset($this->proxy)) {
  440.             $ret = curl_setopt($this->_ch, CURLOPT_PROXY, $this->proxy);
  441.         }
  442.   
  443.         if (isset($this->proxyUser) || isset($this->proxyPassword)) {
  444.             $ret = curl_setopt($this->_ch, CURLOPT_PROXYUSERPWD, $this->proxyUser . ':' . $this->proxyPassword);
  445.         }
  446.  
  447.         if (is_bool($this->verifyPeer)) {
  448.             if(!$this->setOption(CURLOPT_SSL_VERIFYPEER,$this->verifyPeer)) {
  449.                 return PEAR::raiseError('Error setting CURLOPT_SSL_VERIFYPEER');
  450.             } 
  451.         }
  452.  
  453.         if (is_numeric($this->verifyHost) && $this->verifyHost >= 0 &&
  454.             $this->verifyHost <= 2) {
  455.             if(!$this->setOption(CURLOPT_SSL_VERIFYHOST,$this->verifyHost)) {
  456.                 return PEAR::raiseError('Error setting CURLOPT_SSL_VERIFYPEER');
  457.             } 
  458.         }
  459.  
  460.         if (is_bool($this->verifyPeer) && $this->verifyPeer == true) {
  461.             if (isset($this->caInfo) && strlen($this->caInfo)) {
  462.                 if (file_exists($this->caInfo)) {
  463.                     if (!$this->setOption(CURLOPT_CAINFO,$this->caInfo)) { 
  464.                         return PEAR::raiseError('Error setting CURLOPT_CAINFO');
  465.                     }
  466.                 } else {
  467.                     return PEAR::raiseError('Could not find CA info: '.$this->caInfo);
  468.                 }
  469.             }
  470.  
  471.             if (isset($this->caPath) && is_string($this->caPath)) {
  472.                 if (!$this->setOption(CURLOPT_CAPATH,$this->caPath)) {
  473.                     return PEAR::raiseError('Error setting CURLOPT_CAPATH');
  474.                 }
  475.             }
  476.         }
  477.       
  478.         // Transfer type
  479.         if (isset($this->type)) {
  480.             switch (strtolower($this->type)) {
  481.             case 'post':
  482.                 $ret = curl_setopt($this->_ch, CURLOPT_POST, true);
  483.                 break;
  484.             case 'put':
  485.                 $ret = curl_setopt($this->_ch, CURLOPT_PUT, true);
  486.                 break;
  487.             }
  488.         }
  489.       
  490.         // Transfer upload, etc. related
  491.         if (isset($this->file)) {
  492.             if (!file_exists($this->file)) {
  493.                 return PEAR::raiseError('File does not exist: '.$this->file);
  494.             }
  495.  
  496.             $this->_fp = fopen($this->file,'r');
  497.             if (!is_resource($this->_fp)) {
  498.                 return PEAR::raiseError('Could not open file: '.$this->file);
  499.             }
  500.  
  501.             if (!isset($this->fileSize)) {
  502.                 $this->fileSize = filesize($this->file);
  503.             }
  504.         
  505.             $ret = curl_setopt($this->_ch, CURLOPT_INFILE, $this->_fp);
  506.             $ret = curl_setopt($this->_ch, CURLOPT_INFILESIZE, $this->fileSize);
  507.             $ret = curl_setopt($this->_ch, CURLOPT_UPLOAD, true);
  508.         }
  509.       
  510.         if (isset($this->fields)) {
  511.             if (!isset($this->type)) {
  512.                 $this->type = 'post';
  513.                 $ret = curl_setopt($this->_ch, CURLOPT_POST, true);
  514.             }
  515.  
  516.             // If fields is an array then turn it into a string. Somtimes
  517.             // cURL doesn't like fields as an array.
  518.             if (is_array($this->fields)) {
  519.                 $sets = array();
  520.                 foreach ($this->fields as $key => $val) {
  521.                     $sets[] = $key . '=' . urlencode($val);
  522.                 } 
  523.  
  524.                 $fields = implode('&',$sets);
  525.             } else {
  526.                 $fields = $this->fields;
  527.             }
  528.         
  529.             $ret = curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $fields);
  530.         }
  531.       
  532.         // Error related
  533.         if ($this->progress === true) {
  534.             $ret = curl_setopt($this->_ch, CURLOPT_PROGRESS, true);
  535.         }
  536.       
  537.         if ($this->verbose === true) {
  538.             $ret = curl_setopt($this->_ch, CURLOPT_VERBOSE, true);
  539.         }
  540.       
  541.         if ($this->mute !== true) {
  542.             $ret = curl_setopt($this->_ch, CURLOPT_MUTE, false);
  543.         }
  544.   
  545.         // If a Location: header is passed then follow it
  546.         $ret = curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, $this->followLocation);
  547.   
  548.         // If a timeout is set and is greater then zero then set it
  549.         if (is_numeric($this->timeout) && $this->timeout > 0) {
  550.             $ret = curl_setopt($this->_ch, CURLOPT_TIMEOUT, $this->timeout);
  551.         }
  552.   
  553.         if (isset($this->userAgent)) {
  554.             $ret = curl_setopt($this->_ch, CURLOPT_USERAGENT, $this->userAgent);
  555.         }
  556.   
  557.         // Cookies
  558.         if (is_array($this->cookies) && count($this->cookies)) {
  559.             $cookieData = '';
  560.             foreach ($this->cookies as $name => $value) {
  561.                 $cookieData = $name . '=' . $value . ';';
  562.             }
  563.       
  564.             $ret = curl_setopt($this->_ch, CURLOPT_COOKIE, $cookieData);
  565.         }
  566.       
  567.         // Other HTTP headers
  568.         if ($this->httpHeaders !== null) {
  569.             if (is_array($this->httpHeaders)) {
  570.                 $ret = curl_setopt($this->_ch, CURLOPT_HTTPHEADER, $this->httpHeaders);
  571.             } else {
  572.                 return PEAR::raiseError('Net_Curl::$httpHeaders must be an array');
  573.             }
  574.         }
  575.   
  576.         $ret = curl_exec($this->_ch);
  577.  
  578.         // Close the file before we return anything
  579.         if (is_resource($this->_fp)) {
  580.             fclose($this->_fp);
  581.         }
  582.  
  583.         if (curl_errno($this->_ch)) { 
  584.             return PEAR::raiseError(curl_error($this->_ch), curl_errno($this->_ch));
  585.         }
  586.  
  587.         // Check to make sure we get a 2XX/3XX code and not a 404 or something.
  588.         $info = $this->getInfo();
  589.         if (!isset($info['http_code'])) {
  590.             return PEAR::raiseError('Unknown or invalid HTTP response');
  591.         } else {
  592.             $type = substr($info['http_code'],0,1);
  593.             if ($type != 2 && $type != 3) {
  594.                 return PEAR::raiseError('Unexpected HTTP code: '.$info['http_code']);
  595.             }
  596.         }
  597.       
  598.         return $ret;
  599.     }
  600.     // }}}
  601.     // {{{ setOption($option, $value)
  602.     /**
  603.      * setOption
  604.      *
  605.      * Set a option for your cURL session. Please note that the cURL handler
  606.      * is NOT created before execute(). This is for error checking purposes.
  607.      * You should use setOption() in the following manner:
  608.      *
  609.      * <code>
  610.      * <?php
  611.      *
  612.      * require_once('Net/Curl.php'); 
  613.      * $curl = & new Net_Curl('http://www.example.com');
  614.      * $check = $curl->create();
  615.      * if (!PEAR::isError($check)) {
  616.      *     $curl->setOption(CURLOPT_FOO,'bar');
  617.      *     $result = $curl->execute();
  618.      *     if (!PEAR::isError($result)) {
  619.      *         echo $result;
  620.      *     }
  621.      * }
  622.      *
  623.      * ?>
  624.      * </code> 
  625.      * 
  626.      * @author Joe Stump <joe@joestump.net>
  627.      * @access public
  628.      * @param int $option cURL constant (ie. CURLOPT_URL)
  629.      * @param mixed $value
  630.      * @return boolean
  631.      */
  632.     function setOption($option, $value)
  633.     {
  634.         if (is_resource($this->_ch)) {
  635.             return curl_setopt($this->_ch, $option, $value);
  636.         }
  637.  
  638.         return false;
  639.     }
  640.     // }}}
  641.     // {{{ getInfo()
  642.     /**
  643.      * getInfo
  644.      *
  645.      * Returns the info from the cURL session. PEAR_Error if you try and run
  646.      * this before you execute the session.
  647.      *
  648.      * @author Joe Stump <joe@joestump.net> 
  649.      * @access public
  650.      * @return mixed PEAR_Error if there is no resource, info on success
  651.      */
  652.     function getInfo()
  653.     {
  654.         if (is_resource($this->_ch)) {
  655.             return curl_getinfo($this->_ch);
  656.         }
  657.  
  658.         return PEAR::isError('cURL handler does not exist!');
  659.     }
  660.     // }}}
  661.     // {{{ create()
  662.     /**
  663.      * create
  664.      *
  665.      * Create a cURL resource. If curl_init() doesn't exist or we could not
  666.      * create a resource it will error out.
  667.      *
  668.      * @author Joe Stump <joe@joestump.net>
  669.      * @return mixed PEAR_Error on failure, true on success
  670.      */
  671.     function create()
  672.     {
  673.         if (!function_exists('curl_init')) {
  674.             return PEAR::raiseError('Function curl_init() not found');
  675.         }
  676.  
  677.         $this->_ch = curl_init();
  678.         if (!is_resource($this->_ch)) {
  679.             return PEAR::raiseError('Could not initialize cURL handler');
  680.         }
  681.  
  682.         return true;
  683.     }
  684.     // }}}
  685.     // {{{ verboseAll()
  686.     /**
  687.      * Set a verbose output
  688.      *
  689.      * Turns on super debugging mode by not suppressing errors, turning on
  690.      * verbose mode, showing headers and displaying progress.
  691.      *
  692.      * @access public
  693.      * @author David Costa <gurugeek@php.net>
  694.      * @return void
  695.      */
  696.     function verboseAll() 
  697.     {
  698.         $this->verbose = true;
  699.         $this->mute = false;
  700.         $this->header = true;
  701.         $this->progress = true;
  702.     }
  703.     // }}}
  704.     // {{{ verbose_all()
  705.     /**
  706.      * Set a verbose output
  707.      *
  708.      * @access public
  709.      * @author David Costa <gurugeek@php.net>
  710.      * @deprecated
  711.      */
  712.     function verbose_all()
  713.     {
  714.         $this->verboseAll();
  715.         PEAR::raiseError('Net_Curl::verbose_all() is deprecated! Please use Net_Curl::verboseAll()'." <br />\n",null,PEAR_ERROR_PRINT);
  716.         
  717.     }
  718.     // }}}
  719.     // {{{ close()
  720.     /**
  721.      * Closes the curl transfer and finishes the object (kinda ;)
  722.      *
  723.      * @access public
  724.      * @author Sterling Hughes <sterling@php.net>
  725.      * @return void
  726.      * @since  PHP 4.0.5
  727.      */
  728.     function close()
  729.     {
  730.         if (is_resource($this->_ch)) {
  731.             curl_close($this->_ch);
  732.         }
  733.     }
  734.     // }}}
  735.     // {{{ _mapDeprecatedVariables()
  736.     /**
  737.      * _mapDeprecatedVariables
  738.      *
  739.      * Maps deprecated variables into the appropriate places. It also throws
  740.      * the necessary notices.
  741.      *
  742.      * @author Joe Stump <joe@joestump.net>
  743.      * @access private
  744.      * @return void
  745.      */
  746.     function _mapDeprecatedVariables() {
  747.         $bad = array();
  748.         if ($this->follow_location !== false) {
  749.             if ($this->follow_location > 0) {
  750.                 $this->followLocation = true;
  751.             } else {
  752.                 $this->followLocation = false;
  753.             }
  754.  
  755.             $bad[] = array('follow_location','followLocation');
  756.         }
  757.  
  758.         if ($this->return_transfer !== false) {
  759.             if ($this->return_transfer > 0) {
  760.                 $this->returnTransfer = true;
  761.             } else {
  762.                 $this->returnTransfer = false;
  763.             }
  764.  
  765.             $bad[] = array('return_transfer','returnTransfer');
  766.         }
  767.  
  768.         if ($this->file_size !== false) {
  769.             $this->fileSize = $this->file_size;
  770.             $bad[] = array('file_size','fileSize');
  771.         }
  772.  
  773.         if ($this->http_headers !== false) {
  774.             $this->httpHeaders = $this->http_headers;
  775.             $bad[] = array('http_headers','httpHeaders');
  776.         }
  777.  
  778.         foreach ($bad as $map) {
  779.             PEAR::raiseError('Net_Curl::$'.$map[0].' is deprecated! Please use Net_Curl::$'.$map[1]." instead! <br />\n",null,PEAR_ERROR_PRINT);
  780.         }
  781.     }
  782.     // {{{ __destruct()
  783.     /**
  784.      * __destruct 
  785.      * 
  786.      * PHP 5.x destructor. Runs Net_Curl::close() to make sure we close our
  787.      * cURL connection.
  788.      * 
  789.      * @author Joe Stump <joe@joestump.net>  
  790.      * @see Net_Curl::close()
  791.      */
  792.     function __destruct()
  793.     {
  794.         $this->close();
  795.     }
  796.     // }}}
  797. }
  798.  
  799. ?>
  800.