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

Truncated answers #131

Closed
josecdv opened this issue Apr 23, 2019 · 3 comments
Closed

Truncated answers #131

josecdv opened this issue Apr 23, 2019 · 3 comments
Labels

Comments

@josecdv
Copy link

josecdv commented Apr 23, 2019

Good Morning.

I use ReactPHP to launch several API calls asynchronously, but many of the answers I recover it is not complete, I only recover a part of them.

When I make the same requests using cURL instead of ReactPHP, I get the complete answer.

The heaviest response I get is 1.1Mb.

The script that I use is:


<?php

require __DIR__ . '/vendor/autoload.php';

// Show errors.
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Dependencies.
$loop = \React\EventLoop\Factory::create();
$client = new \Clue\React\Buzz\Browser($loop);

$urlList = [
	'http://92.190.147.10:5000/fbdownload/RS_LowFareSearch_9448_142812.txt?_sid=%22Kl7Mhtd7jHu9Q16B0NEN852313%22&mode=open&dlink=%222f7765622f6c6f67732f38342e3233322e342e38362f50524f442f666c69676874732f323031392f4170722f32322f52535f4c6f77466172655365617263685f393434385f3134323831322e747874%22&stdhtml=true&SynoToken=glP0nAeHRpcvk',
	'http://92.190.147.10:5000/fbdownload/RS_LowFareSearch_6398_002611.txt?_sid=%22Kl7Mhtd7jHu9Q16B0NEN852313%22&mode=open&dlink=%222f7765622f6c6f67732f38342e3233322e342e38362f50524f442f666c69676874732f323031392f4170722f32322f52535f4c6f77466172655365617263685f363339385f3030323631312e747874%22&stdhtml=true&SynoToken=glP0nAeHRpcvk',
	'http://92.190.147.10:5000/fbdownload/RS_LowFareSearch_6398_000157.txt?_sid=%22Kl7Mhtd7jHu9Q16B0NEN852313%22&mode=open&dlink=%222f7765622f6c6f67732f38342e3233322e342e38362f50524f442f666c69676874732f323031392f4170722f32322f52535f4c6f77466172655365617263685f363339385f3030303135372e747874%22&stdhtml=true&SynoToken=glP0nAeHRpcvk',
	'http://92.190.147.10:5000/fbdownload/RS_LowFareSearch_5353_221705.txt?_sid=%22Kl7Mhtd7jHu9Q16B0NEN852313%22&mode=open&dlink=%222f7765622f6c6f67732f38342e3233322e342e38362f50524f442f666c69676874732f323031392f4170722f32322f52535f4c6f77466172655365617263685f353335335f3232313730352e747874%22&stdhtml=true&SynoToken=glP0nAeHRpcvk',
	'http://92.190.147.10:5000/fbdownload/RS_LowFareSearch_9448_105851.txt?_sid=%22Kl7Mhtd7jHu9Q16B0NEN852313%22&mode=open&dlink=%222f7765622f6c6f67732f38342e3233322e342e38362f50524f442f666c69676874732f323031392f4170722f32322f52535f4c6f77466172655365617263685f393434385f3130353835312e747874%22&stdhtml=true&SynoToken=glP0nAeHRpcvk'
]; 
$headerList = [];
$timeout = 15;
$responseList = [];
$start = microtime(true);

foreach ($urlList as $url) 
{
	\React\Promise\Timer\timeout($client->get($url, $headerList)->then(
	function (\Psr\Http\Message\ResponseInterface $rawResponse) use (&$responseList)
	{
		$responseList[] = (string)$rawResponse->getBody();
	},
	function (\Clue\React\Buzz\Message\ResponseException $e) use (&$responseList)
	{
		$responseList[] = (string)$e->getResponse()->getBody();
	}
), $timeout, $loop);
}

// Run asynchronously.
$loop->run();

// Get responses.
$i = 1;
foreach ($responseList as $response) 
{
	echo '<h1>RESPUESTA ', $i ,'</h1>';
	echo '<pre>', htmlentities($response), '</pre>';
	$i++;
}

echo '<h6>Runtime ', round(microtime(true) - $start), '</h6>';

Thanks.

Regards.

@clue clue added the question label Apr 23, 2019
@clue
Copy link
Owner

clue commented Apr 23, 2019

@josecdv Thanks for reporting, this shouldn't have happened! I've just tried your script locally and can not reproduce the problem you're seeing. All request bodies have the exact same size as their respective Content-Length request header, so I don't see anything that could be truncated.

That being said, there's still potential for an "incomplete" response over unreliable networks. If the network is somehow interrupted, the response will just end in the middle of the transfer, while the whole response should fail (arguably). This will be addressed upstream via reactphp/http-client#92 and in this library via #102.

This is also covered by our test suite and has been used in production for years already. I don't see anything that could cause this over a reliable network connection, so this is rarely an issue in the applications I've seen. Additionally, using HTTPS may help mitigate this transport layer problem, making it even less of a problem in many real world applications.

I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can reopen this 👍

@clue clue closed this as completed Apr 23, 2019
@josecdv
Copy link
Author

josecdv commented Apr 23, 2019

@josecdv Thanks for reporting, this shouldn't have happened! I've just tried your script locally and can not reproduce the problem you're seeing. All request bodies have the exact same size as their respective Content-Length request header, so I don't see anything that could be truncated.

That being said, there's still potential for an "incomplete" response over unreliable networks. If the network is somehow interrupted, the response will just end in the middle of the transfer, while the whole response should fail (arguably). This will be addressed upstream via reactphp/http-client#92 and in this library via #102.

This is also covered by our test suite and has been used in production for years already. I don't see anything that could cause this over a reliable network connection, so this is rarely an issue in the applications I've seen. Additionally, using HTTPS may help mitigate this transport layer problem, making it even less of a problem in many real world applications.

I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can reopen this +1

Thank you! We take a look at the links you mention.

@josecdv
Copy link
Author

josecdv commented Apr 23, 2019

Hello! In case someone has the same case of receiving truncated responses, I have been solved by updating clue / buzz-react to version 2.6.

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

No branches or pull requests

2 participants