Example #1
0
 /**
  * Runs a functional test
  */
 function run_test()
 {
     header('content-type: text/plain');
     $http = new http_client('localhost', '80');
     if ($http->open()) {
         echo $http->get('/test/foo.txt');
         $http->close();
     }
 }
Example #2
0
 function download($url, $dest = null)
 {
     if (preg_match('/([A-Za-z0-9]+):\\/\\/([^\\/]+)\\/(.*)/', $url, $scan)) {
         list($scan, $proto, $server, $path) = $scan;
         $proto = strtolower($proto);
         if ($dest) {
             if (is_dir($dest)) {
                 $dest = $this->assign_name($dest, basename($path));
             }
             $fp = fopen($dest, 'w');
             switch ($proto) {
                 case 'http':
                     require_once "socket.php";
                     require_once "net/http_client.php";
                     $http = new http_client($server, 80);
                     $http->open();
                     fwrite($fp, $http->get('/' . $path));
                     $http->close();
                     break;
             }
             fclose($fp);
         } else {
             switch ($proto) {
                 case 'http':
                     require_once "socket.php";
                     require_once "net/http_client.php";
                     $http = new http_client($server, 80);
                     $http->open();
                     $buff = $http->get('/' . $path);
                     $http->close();
                     return $buff;
                     break;
             }
         }
     }
     return $dest;
 }