Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

large body produces curl error #831

Closed
Svennisen opened this issue Sep 24, 2014 · 3 comments
Closed

large body produces curl error #831

Svennisen opened this issue Sep 24, 2014 · 3 comments

Comments

@Svennisen
Copy link

Using php 5.5.9 on ubuntu 14.04, guzzle works fine until you try to post a larger body with it.
The error is also fixed if you use another adapter:

$client = new GuzzleHttp\Client(['adapter' => new GuzzleHttp\Adapter\StreamAdapter(new GuzzleHttp\Message\MessageFactory())]);

Not sure if this is a configuration error on my side or a bug in guzzle.

My code looks like this:

    $res = $client->post("https://api.mailgun.net/v2/$mg_domain/messages", [
        'auth' =>  ['api', $mailgun_apikey],
        'query' => [
                            'from' => 'somemail@foo.com',
                            'to' => $to,
                            'subject' => $subject,
                            'text' => $text,
                            'html' => $html
                ]
    ]);

error log output:

PHP Fatal error:  Uncaught exception 'GuzzleHttp\Exception\AdapterException' with message 'cURL error 23: Failed writing body (0 != 8)' in /vagrant/vendor/guzzle
http/guzzle/src/Adapter/Curl/CurlAdapter.php:109
Stack trace:
#0 /vagrant/vendor/guzzlehttp/guzzle/src/Adapter/Curl/CurlAdapter.php(91): GuzzleHttp\Adapter\Curl\CurlAdapter->handleError(Object(GuzzleHttp\Adapter\Transaction), Array, Resource id #16)
#1 /vagrant/vendor/guzzlehttp/guzzle/src/Adapter/StreamingProxyAdapter.php(34): GuzzleHttp\Adapter\Curl\CurlAdapter->send(Object(GuzzleHttp\Adapter\Transaction))
#2 /vagrant/vendor/guzzlehttp/guzzle/src/Client.php(193): GuzzleHttp\Adapter\StreamingProxyAdapter->send(Object(GuzzleHttp\Adapter\Transaction))
#3 /vagrant/vendor/guzzlehttp/guzzle/src/Client.php(181): GuzzleHttp\Client->send(Object(GuzzleHttp\Message\Request))
#4 /vagrant/www/core.php(537): GuzzleHttp\Client->post('https://api.mai...', Array)
#5 /vagrant/www/classes/Email.php(70): mailg('myname@gmail...', 'Welcome to Web...', Array)
#6 /vagrant/www/POS/ajax/p in /vagrant/vendor/guzzlehttp/guzzle/src/Event/RequestEvents.php on line 114
@mtdowling
Copy link
Member

Is this request actually sending a body? I just see a query string. Maybe the query is too long and causing a weird error. What does the output look like if you enable debug output?

On Sep 23, 2014, at 11:46 PM, Svennisen notifications@github.com wrote:

Using php 5.5.9 on ubuntu 14.04, guzzle works fine until you try to post a larger body with it.
The error is also fixed if you use another adapter:

$client = new GuzzleHttp\Client(['adapter' => new GuzzleHttp\Adapter\StreamAdapter(new GuzzleHttp\Message\MessageFactory())]);

Not sure if this is a configuration error on my side or a bug in guzzle.

My code looks like this:

$res = $client->post("https://api.mailgun.net/v2/$mg_domain/messages", [
    'auth' =>  ['api', $mailgun_apikey],
    'query' => [
                        'from' => 'somemail@foo.com',
                        'to' => $to,
                        'subject' => $subject,
                        'text' => $text,
                        'html' => $html
            ]
]);

error log output:

PHP Fatal error: Uncaught exception 'GuzzleHttp\Exception\AdapterException' with message 'cURL error 23: Failed writing body (0 != 8)' in /vagrant/vendor/guzzle
http/guzzle/src/Adapter/Curl/CurlAdapter.php:109
Stack trace:
#0 /vagrant/vendor/guzzlehttp/guzzle/src/Adapter/Curl/CurlAdapter.php(91): GuzzleHttp\Adapter\Curl\CurlAdapter->handleError(Object(GuzzleHttp\Adapter\Transaction), Array, Resource id #16)
#1 /vagrant/vendor/guzzlehttp/guzzle/src/Adapter/StreamingProxyAdapter.php(34): GuzzleHttp\Adapter\Curl\CurlAdapter->send(Object(GuzzleHttp\Adapter\Transaction))
#2 /vagrant/vendor/guzzlehttp/guzzle/src/Client.php(193): GuzzleHttp\Adapter\StreamingProxyAdapter->send(Object(GuzzleHttp\Adapter\Transaction))
#3 /vagrant/vendor/guzzlehttp/guzzle/src/Client.php(181): GuzzleHttp\Client->send(Object(GuzzleHttp\Message\Request))
#4 /vagrant/www/core.php(537): GuzzleHttp\Client->post('https://api.mai...', Array)
#5 /vagrant/www/classes/Email.php(70): mailg('myname@gmail...', 'Welcome to Web...', Array)
#6 /vagrant/www/POS/ajax/p in /vagrant/vendor/guzzlehttp/guzzle/src/Event/RequestEvents.php on line 114

Reply to this email directly or view it on GitHub.

@Svennisen
Copy link
Author

I made the mistake of using "query" instead of "body". I guess the mailgun api accepted both, and it worked without curl. I would suggest putting in a limit for the query string in the library to make this user error more clear?

@mtdowling
Copy link
Member

There are too many unknowns at this point to provide enough information to add guards in guzzle around this. It could also be a weird server error triggering this (I know some servers have a limit on the size of the query string). Maybe you could open an issue on libcurl and provide verbose curl output for the failing case.

On Sep 24, 2014, at 12:19 AM, Svennisen notifications@github.com wrote:

I made the mistake of using "query" instead of "body". I guess the mailgun api accepted both, and it worked without curl. I would suggest putting in a limit for the query string in the library to make this user error more clear?


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants