Code Monkey home page Code Monkey logo

yacurl's Introduction

YACurL

Yet Another Curl Library - an open source curl library for PHP

Public Methods:

void __construct([array $config]);
string get(string $url);
string post(string $url, array $param, [int $type = 0], [bool $use_http_build_query = true]);

Note: [squared $arguments] are optional

Example 1: Set cookie prefix, set follow location, enable debug

$config = array(
	'cookie_prefix' => 'mypref',
	'follow_location' => 'true',
	'debug' => 'true'
);
$curl = New YACurL($config);
$curl->get('www.mysite.com');
//post encoded as application/x-www-form-urlencoded
$curl->post('www.mysite.com', array('user' => 'myuser', 'pass' => 'mypass'));
//post encoded as multipart/form-data
$response = $curl->post('www.mysite.com', array('user' => 'myuser', 'pass' => 'mypass'), 1);
echo $response;

Example 2: Set delay before http requests

//static delay
$config = array('delay' => 5);
$curl = New YACurL($config);

//random delay from 1 to 5 seconds
$config = array(
	'delay' => array(1,5);
);
$curl = New YACurL($config);

Example 3: Load it in codeigniter

$this->load->library('yacurl', $config);
$this->yacurl->get('www.mysite.com');

Info about $use_http_build_query

If $use_http_build_query is false, form param will be encoded by internal routine instead of http_build_query().

This custom routine is similar to http_build_query() but ignores "*" char.

Example:

  • http_build_query('abc*def g') = abc%2Aef%20g
  • Internal routine encodes it as abc*def%20g.

Configuration

  • (array) header
  • (string) encoding
  • (string) cookie_prefix
  • (bool) auto_referer
  • (bool) return_transfer
  • (bool) follow_location
  • (int) delay
  • (bool) debug

Default:

 $_curl_config = array(
 		'header' => array(
 			'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
 			'Accept-Language: it-IT',
 			'Accept-Encoding: gzip,deflate,sdch' 
 		),
 		'encoding' => 'gzip',
 		'cookie_prefix' => '',
 		'auto_referer' => true,
 		'return_transfer' => true,
 		'follow_location' => false,
 		'delay' => 0,
 		'debug' => true
 );

yacurl's People

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  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.