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

Error when sending large messages over secure HTTPS with older PHP versions #60

Closed
pwhelan opened this issue Jul 15, 2016 · 9 comments · Fixed by #109
Closed

Error when sending large messages over secure HTTPS with older PHP versions #60

pwhelan opened this issue Jul 15, 2016 · 9 comments · Fixed by #109
Labels
Milestone

Comments

@pwhelan
Copy link

pwhelan commented Jul 15, 2016

When sending large contents via POST, specifically images (~90kb+) the connection simply hangs. I have already filed the same bug in for the WyriHaximus guzzle adapter here: WyriHaximus/react-guzzle-psr7#10.

Here is some short example code:

<?php

require_once 'vendor/autoload.php';


$mp = new p3k\Multipart;
$mp->addPart('field', 'value');
$mp->addFile('file', 'large-image', 'image/jpeg');

$url = "https://example.com";

$loop = React\EventLoop\Factory::create();
$dnsFactory = new React\Dns\Resolver\Factory();
$dns = $dnsFactory->createCached('192.168.2.1', $loop);
$factory = new React\HttpClient\Factory();
$client = $factory->create($loop, $dns);

$loop->nextTick(function() use ($client, $url, $mp) {

    $request = $client->request("POST", $url, [
        'Content-Type'      => $mp->contentType(),
        'Content-Length'    => strlen($mp->data())
    ]);

    $request->on('response', function($response) {
        print "WE HAVE RESPONSE: ".$response->getCode()."\n";
        print_r($response->getHeaders());
        $response->on('data', function($data, $response) {
            print "DATA ...\n";
            print $data;
        });
        $response->on('end', function() {
            die("IT'S OVER!\n");
        });
    });

    $request->end($mp->data());
});

while (1) $loop->run();
print "DONE!\n";

You will need a URL to POST to as well as an image file to send. Both should not be hard to get a hold of to test this.

@WyriHaximus
Copy link
Member

ping @clue, could this possibly be in the SSL part of react/socket-client?

@pwhelan
Copy link
Author

pwhelan commented Jul 15, 2016

This also happens at the socket-client level, this is an example (without actually parsing the response to exit cleanly):

<?php

require_once 'vendor/autoload.php';

$url = "https://example.com";

$mp = new p3k\Multipart;
$mp->addPart('field', ''value');
$mp->addFile('photo', 'small-98kb.jpeg'', 'image/jpeg');

$loop = React\EventLoop\Factory::create();
$dnsFactory = new React\Dns\Resolver\Factory();
$dns = $dnsFactory->createCached('192.168.2.1', $loop);
$tcpConnector = new React\SocketClient\TcpConnector($loop);
$dnsConnector = new React\SocketClient\DnsConnector($tcpConnector, $dns);
$connector = new React\SocketClient\SecureConnector($dnsConnector, $loop, ['verify_peer' => false]);


$loop->nextTick(function() use ($connector, $url, $mp) {

    $urlparts = parse_url($url);

    $connector->create($urlparts['host'], 443)
        ->then(function (React\Stream\Stream $stream) use ($mp, $urlparts) {

            $stream->write(
                "POST {$urlparts['path']} HTTP/1.0\r\n" .
                "Host: {$urlparts['host']}\r\n" .
                "Content-Type: ".$mp->contentType()."\r\n" .
                "Content-Length: ".strlen($mp->data())."\r\n" .
                "Connection: close\r\n" .
                "\r\n" .
                $mp->data()
            );

            $stream->on('data', function($data) {
                print "DATA = \n{$data}\n";
            });

            $stream->on('close', function() {
                print "DONE\n";
            });

            //$stream->end();
        });

});

while (1) $loop->run();

@pwhelan
Copy link
Author

pwhelan commented Jul 15, 2016

I also tested it with a small file and it worked perfectly.

@clue
Copy link
Member

clue commented Jul 17, 2016

the connection simply hangs

Thanks for letting us know, but from the details you've posted, the problem appears to be a bit unclear to me. Perhaps you can elaborate: What exactly is hanging here, what is the expected behavior and how does the observed behavior differ?

There are many different possible sources of problems, perhaps this helps pinpointing this. Thanks!

Could we perhaps be running into HTTP's keepalive connection timeouts here?

@clue
Copy link
Member

clue commented Oct 6, 2016

Ping @pwhelan, and new info on this on?

@pwhelan
Copy link
Author

pwhelan commented Oct 11, 2016

I fixed it by using by own external micro service in golang to upload files via https. As far as I can tell no one else has followed up with the different issues to finally fix this. From what I can tell it seems to be a problem either in PHP itself or in the way it is handled by react socket client.

@clue
Copy link
Member

clue commented Oct 12, 2016

From what I can tell it seems to be a problem either in PHP itself or […]

Please provide us with some more details so we can look into this (see above). So far, nobody has managed to run into the issue you're seeing, so I'm not sure there's a problem in any of the mentioned components in the first place.

@clue
Copy link
Member

clue commented Mar 10, 2017

We still need some more information / confirmation here, but I suppose this may be related to reactphp/stream#64, which indicates this is a general issues with sending large chunks over a TLS connection.

@clue
Copy link
Member

clue commented May 19, 2017

We have managed to reproduce and pin point this to a bug in PHP that has recently been fixed in 7.1.4 and 7.0.18. We're planning to provide a work around for this for affected versions via reactphp/socket#105 👍

@clue clue removed the help wanted label May 19, 2017
@clue clue changed the title Sending large POST body via SSL/TLS times out Error when sending large messages over secure HTTPS with older PHP versions Aug 25, 2017
@clue clue added this to the v0.5.5 milestone Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants