home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phptriad / phptriad2-2-1.exe / php / pear / PEAR / Remote.php < prev    next >
PHP Script  |  2001-11-13  |  4KB  |  102 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2001 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Stig Bakken <ssb@fast.no>                                   |
  17. // |                                                                      |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: Remote.php,v 1.4.2.1 2001/11/13 01:26:49 ssb Exp $
  21.  
  22. require_once 'PEAR.php';
  23.  
  24. /**
  25.  * This is a class for doing remote operations against the central
  26.  * PEAR database.
  27.  */
  28. class PEAR_Remote extends PEAR
  29. {
  30.     // {{{ properties
  31.  
  32.     var $config_object = null;
  33.  
  34.     // }}}
  35.  
  36.     // {{{ PEAR_Remote(config_object)
  37.  
  38.     function PEAR_Remote($config_object)
  39.     {
  40.         $this->PEAR();
  41.         $this->config_object = $config_object;
  42.     }
  43.  
  44.     // }}}
  45.  
  46.     // {{{ call(method, [args...])
  47.  
  48.     function call($method)
  49.     {
  50.         if (!extension_loaded("xmlrpc")) {
  51.             return $this->raiseError("xmlrpc support not loaded");
  52.         }
  53.         $params = array_slice(func_get_args(), 1);
  54.         $request = xmlrpc_encode_request($method, $params);
  55.         $server_host = $this->config_object->get("master_server");
  56.         if (empty($server_host)) {
  57.             return $this->raiseError("PEAR_Remote::call: no master_server configured");
  58.         }
  59.         $server_port = 80;
  60.         $fp = @fsockopen($server_host, $server_port);
  61.         if (!$fp) {
  62.             return $this->raiseError("PEAR_Remote::call: fsockopen(`$server_host', $server_port) failed");
  63.         }
  64.         $len = strlen($request);
  65.         fwrite($fp, ("POST /xmlrpc.php HTTP/1.0\r\n".
  66.                      "Host: $server_host:$server_port\r\n".
  67.                      "Content-type: text/xml\r\n".
  68.                      "Content-length: $len\r\n".
  69.                      "\r\n$request"));
  70.         $response = '';
  71.         while (trim(fgets($fp, 2048)) != ''); // skip headers
  72.         while ($chunk = fread($fp, 10240)) {
  73.             $response .= $chunk;
  74.         }
  75.         fclose($fp);
  76.         $ret = xmlrpc_decode($response);
  77.         if (is_array($ret) && isset($ret['__PEAR_TYPE__'])) {
  78.             if ($ret['__PEAR_TYPE__'] == 'error') {
  79.                 if (isset($ret['__PEAR_CLASS__'])) {
  80.                     $class = $ret['__PEAR_CLASS__'];
  81.                 } else {
  82.                     $class = "PEAR_Error";
  83.                 }
  84.                 if ($ret['code']     === '') $ret['code']     = null;
  85.                 if ($ret['message']  === '') $ret['message']  = null;
  86.                 if ($ret['userinfo'] === '') $ret['userinfo'] = null;
  87.                 if (strtolower($class) == 'db_error') {
  88.                     return $this->raiseError(DB::errorMessage($ret['code']),
  89.                                              $ret['code'], null, null,
  90.                                              $ret['userinfo']);
  91.                 } else {
  92.                     return $this->raiseError($ret['message'], $ret['code'],
  93.                                              null, null, $ret['userinfo']);
  94.                 }
  95.             }
  96.         }
  97.     }
  98.  
  99.     // }}}
  100. }
  101.  
  102. ?>