Code Monkey home page Code Monkey logo

httprelay's Introduction

HTTPRelay pear package

GitHub license

License

Copyright (c) 2016 JoungKyun.Kim <http://oops.org> All rights reserved

This program is under BSD license

Description

Request HTTP GET/POST/HEAD or relay recieved query to the other server.

Installation

We recommand to install with pear command cause of dependency pear packages.

1. use pear command

[root@host ~]$ # add pear channel 'pear.oops.org'
[root@host ~]$ pear channel-discover pear.oops.org
Adding Channel "pear.oops.org" succeeded
Discovery of channel "pear.oops.org" succeeded
[root@host ~]$ # add HTTPRelay pear package
[root@host ~]$ pear install oops/HTTPRelay
downloading HTTPRelay-1.0.5.tgz ...
Starting to download HTTPRelay-1.0.5.tgz (5,783 bytes)
...done: 5,783 bytes
downloading myException-1.0.1.tgz ...
Starting to download myException-1.0.1.tgz (3,048 bytes)
...done: 3,048 bytes
install ok: channel://pear.oops.org/myException-1.0.1
install ok: channel://pear.oops.org/HTTPRelay-1.0.5
[root@host ~]$

If you wnat to upgarde version:

[root@host ~]$ pear upgrade oops/HTTPRelay

2. install by hand

Get last release at https://github.com/OOPS-ORG-PHP/HTTPRelay/releases and uncompress pakcage within PHP include_path.

You must need follow dependency pear packages:

Usages

Refence siste: http://pear.oops.org/docs/HTTPRelay/HTTPRelay.html

reference is written by Korean. If you can't read korean, use google translator.

1. GET method

<?php
require_once 'HTTPRelay.php';

// all PHP error handler to myException
set_error_handler ('myException::myErrorHandler');

try {
	$http = new HTTPRelay;

	$buf = $http->fetch ('https://raw.github.com/twbs/bootstrap/master/bower.json', 3);

	if ( $buf === false ) {
		echo 'ERROR:  ' . $http->error . "\n";
		exit;
	}

	$buf = json_decode ($buf);

	print_r ($buf);
	print_r ($http->info);
} catch ( myException $e ) {
	echo $e->Message () . "\n";
	print_r ($e->TraceAsArray ()) . "\n";
	$e->finalize ();
}
?>

2. POST method

<?php
require_once 'HTTPRelay.php';

// all PHP error handler to myException
set_error_handler ('myException::myErrorHandler');

try {
	$http = new HTTPRelay;

	$post = array (
		'name' => 'joungkyun',
		'grade' => 'A plus plus'
	);

	// prototype: string fetch( string $to, [int $tmout = 60], [string $httphost = ''], [array $post = null])
	$buf = $http->fetch ('https://raw.github.com/twbs/bootstrap/master/bower.json', 3, null, $post);

	if ( $buf === false ) {
		echo 'ERROR:  ' . $http->error . "\n";
		exit;
	}

	$buf = json_decode ($buf);

	print_r ($buf);
	print_r ($http->info);
} catch ( myException $e ) {
	echo $e->Message () . "\n";
	print_r ($e->TraceAsArray ()) . "\n";
	$e->finalize ();
}
?>

3. HEAD method

<?php
require_once 'HTTPRelay.php';

// all PHP error handler to myException
set_error_handler ('myException::myErrorHandler');

try {
	$http = new HTTPRelay;

	// prototype: stdClass head( string $to, [int $tmout = 60], [string $httphost = ''])
	$buf = $http->head ('https://raw.github.com/twbs/bootstrap/master/bower.json', 3);

	if ( $buf === false ) {
		echo 'ERROR:  ' . $http->error . "\n";
		exit;
	}

	print_r ($http->info);
	print_r ($buf);
} catch ( myException $e ) {
	echo $e->Message () . "\n";
	print_r ($e->TraceAsArray ()) . "\n";
	$e->finalize ();
}
?>

4. Query relay

<?php
require_once 'HTTPRelay.php';

// all PHP error handler to myException
set_error_handler ('myException::myErrorHandler');

try {
	$header = array (
		'X_RELAY_SERVER' => 'http://this-host',
		'X_REQ_HEADER' => 'addtional request header',
		'X_REQ_HEADER2' => 'addtional request header 2'
	);
	$http = new HTTPRelay ($header);
	// you can set 'form-data' or 'url-encode'
	$http->posttype = 'form-data';

	// prototype: string relay( string $to, [int $tmout = 60], [string $httphost = ''])
	$buf = $http->relay (
		'http://relay-host.domain.com/relaypage/',
		'10',
		'relay-host.domain.com'
	);
	if ( $buf === false )
		throw new myException ($http->error, E_USER_ERROR);
	echo $buf . "\n\n\n";
	print_r ($http->info);
} catch ( myException $e ) {
	printf ("%s\n", $e->Message ());
	print_r ($e->TraceAsArray ()) . "\n";
	$e->finalize ();
}
?>

httprelay's People

Contributors

joungkyun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.