kajna/curli

This package is abandoned and no longer maintained. No replacement package was suggested.

Object-Oriented interface for PHP cUrl extension

0.9.0 2016-06-17 10:20 UTC

This package is not auto-updated.

Last update: 2020-01-28 20:31:42 UTC


README

DUB Version

Lightweight library with object-oriented interface for sending HTTP requests

Installing

This package is available via Composer:

{
  "require": {
    "kajna/curli": "dev-master"
  }
}

Usage examples

Fetching HTML page using GET

try {
	$curli = (new \Curli\Curli())
			->get('http://example.com')
			->close();

	$response = $curli->response();

	echo $response->asText();
} catch(\Exception $e) {
	echo $e->getMessage();
}

Sending and receiving JSON data using PUT with connection timeout

try {
	$data = array('foo' => 'bar');
	$json = json_encode($data);

	$curli = (new \Curli\Curli())
			->setConnectionTimeout(3)
			->setHeader('Content-Type', 'application/json')
			->setHeader('Content-Length', strlen($json))
			->setParams($json)
			->put('http://example.com')
			->close();

	$response = $curli->response();

	print_r($response->asObject());
} catch(\Exception $e) {
	echo $e->getMessage();
}

Sending and receiving XML data using POST

try {
	$data = '<root><foo>bar</foo></root>';

	$curli = (new \Curli\Curli())
			->setUserAgent('curl 7.16.1 (i386-portbld-freebsd6.2) libcurl/7.16.1 OpenSSL/0.9.7m zlib/1.2.3')
			->setHeader('Content-Type', 'text/xml')
			->setHeader('Content-Length', strlen($data))
			->setParams($data)
			->post('http://example.com')
			->close();

	$response = $curli->response();

	print_r($response->asArray());
} catch(\Exception $e) {
	echo $e->getMessage();
}

Author

Author of library is Milos Kajnaco milos@caenazzo.com

Licence

Curli is released under the MIT public license.