Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Md. Rayhan Chowdhury  >  RayHttp  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Script
Class: RayHttp
HTTP client to send requests to Web servers
Author: By
Last change: example for proxy setup.
Date: 2009-06-12 22:39
Size: 2,593 bytes
 

Contents

Class file image Download
<?php 
/**
 * HTTP Client Class Example Script.
 *
 * Example of RayHttp Class Object. 
 *
 *    PHP Version 5
 *
 *
 *    @copyright        Copyright 2006-2008, Md. Rayhan Chowdhury
 *    @package        raynux
 *    @subpackage        raynux.lab.http
 *     @since            version 1.0
 *    @version        $Revision: 113 $
 *     @modifiedby        $LastChangedBy: rayhan $
 *    @lastModified    $Date: 2008-06-15 10:30:19 +0600 (Sun, 15 Jun 2008) $
 *    @author            $Author: rayhan $
 *    @url            $HeadURL: http://localhost/svn/raynux/trunk/labs/example.php $
 *    @website        www.raynux.com
 *  @license         GPL
 */

/**
 * Load the http client.
 */
require_once("rayhttp.php");

/**
 * METHOD GET.
 */

/**
 * Example 1
 * 
 * using default configuration
 * default method is curl.
 * use as a singleton object.
 */
$content RayHttp::getInstance()->get("http://google.com");
$content RayHttp::getInstance()->get("http://google.com/search", array('q' => 'rayhttp'));
$content RayHttp::getInstance()->get("http://google.com/search?q=rayhttp");


/**
 * Example 2
 * 
 * using default configuration but using php native file_get_contetns method.
 * use as a singleton object.
 * static method.
 */
$content RayHttp::getInstance()->setOptions(array('client' => 'php'))->get("http://google.com");
$content RayHttp::getInstance()->setOptions(array('client' => 'php'))->get("http://google.com/search", array('q' => 'rayhttp'));
$content RayHttp::getInstance()->setOptions(array('client' => 'php'))->get("http://google.com/search?q=rayhttp");


/**
 * Example 3
 * 
 * Take Instance Of the object
 */
$http = new RayHttp();
$content $http->get("http://google.com");
$content $http->get("http://google.com/search", array('q' => 'rayhttp'));
$content $http->get("http://google.com/search?q=rayhttp");



/**
 * METHOD POST.
 */

/**
 * Example 4
 * 
 * using default configuration
 */
$content RayHttp::getInstance()->post("http://example.com/", array('name' => 'rayhttp''location' => 'dhaka, bangladesh'));


/**
 * Multiple Instance & Configuration.
 */
RayHttp::getInstance('default'$configs);
RayHttp::getInstance('default2'$configs);

$http RayHttp::getInstance(); // get default instance
$http2 RayHttp::getInstance('default2'); // get default2 instance


$http3 RayHttp::getInstance('default3'$configs); // get default 3 instance
$http3->setOptions($configs); // reconfigure default3 instance;

/**
 * Specify Proxy
 */
RayHttp::getInstance('c')->setCurlOptions(array(CURLOPT_PROXY => '172.19.79.1:3128'))->get("http://www.google.com");