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

PHP Fatal Error when retrieving certain pages. #3177

Closed
triggerx opened this issue Sep 12, 2023 · 4 comments
Closed

PHP Fatal Error when retrieving certain pages. #3177

triggerx opened this issue Sep 12, 2023 · 4 comments

Comments

@triggerx
Copy link

Guzzle version(s) affected: 7.8.0
PHP version: 8.1.17
cURL version: 7.68.0

Description
When trying to retrieve an Instagram profile page, it returns a "429 Too Many Requests" response that causes a PHP Fatal error, as shown below. I realize scraping Instagram is not recommended, but using here to demonstrate the issue I found.

mod_fcgid: stderr: PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://www.instagram.com/facebook/ resulted in a 429 Too Many Requests response in /home/user/.php/composer/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113

How to reproduce
Attempt to get an Instagram Profile, such as https://www.instagram.com/facebook/.

Full PHP code on the page that calls Guzzle:
$url1 = 'https://www.instagram.com/facebook/';

$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $url1);

echo $response->getStatusCode(); // 200
echo $response->getHeaderLine('content-type'); // 'application/json; charset=utf8'

Full Stack Trace
mod_fcgid: stderr: PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://www.instagram.com/facebook/ resulted in a 429 Too Many Requests response in /home/user/.php/composer/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
mod_fcgid: stderr: Stack trace:
mod_fcgid: stderr: #0 /home/user/.php/composer/vendor/guzzlehttp/guzzle/src/Middleware.php(72): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)
mod_fcgid: stderr: #1 /home/user/.php/composer/vendor/guzzlehttp/promises/src/Promise.php(209): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
mod_fcgid: stderr: #2 /home/user/.php/composer/vendor/guzzlehttp/promises/src/Promise.php(158): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
mod_fcgid: stderr: #3 /home/user/.php/composer/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
mod_fcgid: stderr: #4 /home/user/.php/composer/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Promise\TaskQueue->run(true)
mod_fcgid: stderr: #5 /home/user/.php/composer/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn()
mod_fcgid: stderr: #6 /home/user/.php/composer/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
mod_fcgid: stderr: #7 /home/user/.php/composer/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
mod_fcgid: stderr: #8 /home/user/.php/composer/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending()
mod_fcgid: stderr: #9 /home/user/.php/composer/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Promise\Promise->wait()
mod_fcgid: stderr: #10 /home/user/mysitename.com/guzzletest.php(8): GuzzleHttp\Client->request('GET', 'https://www.ins...')
mod_fcgid: stderr: #11 {main}
mod_fcgid: stderr: thrown in /home/user/.php/composer/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

@GrahamCampbell
Copy link
Member

Guzzle is behaving correctly here. I don't know what the purpose of the issue was?

@triggerx
Copy link
Author

Ah, ok, thanks. I'll check the documentation to see what all responses will cause Guzzle to throw a fatal PHP error and see how to work around them. Thanks!

@GrahamCampbell
Copy link
Member

The fatal error is occurring simply because there is an uncaught exception, as per usual PHP behaviour.

@triggerx
Copy link
Author

Thank you Graham... I did indeed find what I was looking for in the documentation (http_errors => false). I know I know... RTFM.

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