.gitignore 0000644 00000000316 15174273274 0006550 0 ustar 00 # Ingore common cruft
.DS_STORE
coverage
# Ignore binary files
guzzle.phar
guzzle-min.phar
# Ignore potentially sensitive phpunit file
phpunit.xml
# Ignore composer generated files
composer.lock
vendor/
.travis.yml 0000644 00000000425 15174273274 0006672 0 ustar 00 language: php
php:
- 5.3
- 5.4
before_script:
- wget --quiet http://getcomposer.org/composer.phar
- php composer.phar install --install-suggests
- cp phpunit.xml.dist phpunit.xml
- ~/.nvm/nvm.sh run default tests/Guzzle/Tests/Http/server.js &
script: sudo phpunit
LICENSE 0000644 00000002126 15174273274 0005566 0 ustar 00 Copyright (c) 2011 Michael Dowling, https://github.com/mtdowling
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. README.md 0000644 00000013445 15174273274 0006046 0 ustar 00 Guzzle, PHP HTTP client and webservice framework
================================================
Guzzle is a game changer in the world of PHP HTTP clients. Guzzle allows you to truly reap the benefits of the HTTP/1.1 spec. No other library makes it easier to manage persistent connections or send requests in parallel.
In addition to taking the pain out of HTTP, Guzzle provides a lightweight framework for creating web service clients. Most web service clients follow a specific pattern: create a client class, create methods for each action, create and execute a cURL handle, parse the response, implement error handling, and return the result. Guzzle takes the redundancy out of this process and gives you the tools you need to quickly build a web service client.
Start truly consuming HTTP with Guzzle.
- [Download the phar](http://guzzlephp.org/guzzle.phar) and include it in your project ([minimal phar](http://guzzlephp.org/guzzle-min.phar))
- Docs: [www.guzzlephp.org](http://www.guzzlephp.org/)
- Forum: https://groups.google.com/forum/?hl=en#!forum/guzzle
- IRC: [#guzzlephp](irc://irc.freenode.net/#guzzlephp) channel on irc.freenode.net
[](http://travis-ci.org/guzzle/guzzle)
Features
--------
- Supports GET, HEAD, POST, DELETE, PUT, and OPTIONS
- Allows full access to request and response headers
- Persistent connections are implicitly managed by Guzzle, resulting in huge performance benefits
- Send requests in parallel
- Cookie sessions can be maintained between requests using the CookiePlugin
- Allows custom entity bodies to be sent in PUT and POST requests, including sending data from a PHP stream
- Responses can be cached and served from cache using the caching reverse proxy plugin
- Failed requests can be retried using truncated exponential backoff
- Entity bodies can be validated automatically using Content-MD5 headers
- All data sent over the wire can be logged using the LogPlugin
- Automatically requests compressed data and automatically decompresses data
- Subject/Observer signal slot system for unobtrusively modifying request behavior
- Supports all of the features of libcurl including authentication, redirects, SSL, proxies, etc
- Web service client framework for building future-proof interfaces to web services
- Full support for [URI templates](http://tools.ietf.org/html/draft-gregorio-uritemplate-08)
HTTP basics
-----------
```php
'***'
));
// Issue a path using a relative URL to the client's base URL
// Sends to http://www.example.com/api/v1/key/***/users
$request = $client->get('users');
$response = $request->send();
// Relative URL that overwrites the path of the base URL
$request = $client->get('/test/123.php?a=b');
// Issue a head request on the base URL
$response = $client->head()->send();
// Delete user 123
$response = $client->delete('users/123')->send();
// Send a PUT request with custom headers
$response = $client->put('upload/text', array(
'X-Header' => 'My Header'
), 'body of the request')->send();
// Send a PUT request using the contents of a PHP stream as the body
// Send using an absolute URL (overrides the base URL)
$response = $client->put('http://www.example.com/upload', array(
'X-Header' => 'My Header'
), fopen('http://www.test.com/', 'r'));
// Create a POST request with a file upload (notice the @ symbol):
$request = $client->post('http://localhost:8983/solr/update', null, array (
'custom_field' => 'my value',
'file' => '@/path/to/documents.xml'
));
// Create a POST request and add the POST files manually
$request = $client->post('http://localhost:8983/solr/update')
->addPostFiles(array(
'file' => '/path/to/documents.xml'
));
// Responses are objects
echo $response->getStatusCode() . ' ' . $response->getReasonPhrase() . "\n";
// Requests and responses can be cast to a string to show the raw HTTP message
echo $request . "\n\n" . $response;
// Create a request based on an HTTP message
$request = RequestFactory::fromMessage(
"PUT / HTTP/1.1\r\n" .
"Host: test.com:8081\r\n" .
"Content-Type: text/plain"
"Transfer-Encoding: chunked\r\n" .
"\r\n" .
"this is the body"
);
```
Send requests in parallel
-------------------------
```php
send(array(
$client->get('users'),
$client->head('messages/123'),
$client->delete('orders/123')
));
} catch (Guzzle\Common\ExceptionCollection $e) {
echo "The following requests encountered an exception: \n";
foreach ($e as $exception) {
echo $exception->getRequest() . "\n" . $exception->getMessage() . "\n";
}
}
```
URI templates
-------------
Guzzle supports the entire URI templates RFC.
```php
'/path/to',
'a' => 'hi',
'data' => array(
'foo' => 'bar',
'mesa' => 'jarjar'
)
));
$request = $client->get('http://www.test.com{+path}{?a,data*}');
```
The generated request URL would become: ``http://www.test.com/path/to?a=hi&foo=bar&mesa=jarajar``
You can specify URI templates and an array of additional template variables to use when creating requests:
```php
'hi'
));
$request = $client->get(array('/{?a,b}', array(
'b' => 'there'
));
```
The resulting URL would become ``http://test.com?a=hi&b=there``
Testing Guzzle
--------------
Here's how to install Guzzle from source to run the unit tests:
```
git clone git@github.com:guzzle/guzzle.git
cd guzzle
composer.phar install --install-suggests
cp phpunit.xml.dist phpunit.xml
phpunit
```
autoload.php 0000644 00000002033 15174273274 0007077 0 ustar 00 'phar://' . __FILE__ . '/src',
'Symfony\\Component\\Validator' => 'phar://' . __FILE__ . '/vendor/symfony/validator',
'Symfony\\Component\\EventDispatcher' => 'phar://' . __FILE__ . '/vendor/symfony/event-dispatcher',
'Doctrine' => 'phar://' . __FILE__ . '/vendor/doctrine/common/lib',
'Monolog' => 'phar://' . __FILE__ . '/vendor/monolog/monolog/src'
);
if (DIRECTORY_SEPARATOR == '/') {
require_once 'phar://' . __FILE__ . '/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';
} else {
require_once 'phar://' . __FILE__ . '\\vendor\\symfony\\class-loader\\Symfony\\Component\\ClassLoader\\UniversalClassLoader.php';
$namespaces = array_filter($namespaces, function($namespace) {
return str_replace('phar:\\\\', 'phar://', str_replace('/', '\\', $namespace));
});
}
$classLoader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$classLoader->registerNamespaces($namespaces);
$classLoader->register();
__HALT_COMPILER(); build.xml 0000644 00000003340 15174273274 0006401 0 ustar 00