getting 502 proxy error while parsing - php

Iam parsing a page and im getting response from that but after some time i.e. after some of the parsing gets done i get this error from the server -
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /file.php.
Reason: Error reading from remote server
and after this my parsing fails.
I even tried sleep() function but it didnt helped and the error still came.
Are they temporarily blocking my ip or what??
What could be the reason for this and how can i parse those pages without getting this error and all ???

Why don't you use CURL to fetch the page contents and then parse them? let me know if this works or you need any help.
--Pinaki

Related

How to show fully the error and remove the truncated?

I am using GuzzleHttp to send post request to another project. But when I have error I can't see all error it is always truncated.
Can anyone know how to remove the (truncated...) so that I can fully see the error?
GuzzleHttp\Exception\ServerException
Server error: POST http://127.0.0.1:8000/api/api resulted in a 500 Internal Server Error response: <!doctype html> <!-- TypeError: Argument 1 passed to Illuminate\Database\Query\Builder::inser (truncated...)
The error is only truncated in the Guzzle Exception message. You find the error in full in the other projects' PHP error log if you enable error logging there -- and -- in the response body.
Right now you've enabled display errors (or you're displaying errors in some variant that inserts the message into a HTML comment), check error logging is enabled and locate the appropriate log file.
Alternatively you can configure Guzzle to not throw on "HTTP errors"[1], verify the response status is 500 and if so have the non-truncated information in the response body.
The truncation is only for convenience as exception messages often end up in some line of their own in the PHP error log (of the applications that don't catch it) and such lines have a common limit of 1024 bytes for portability reasons.
Most details of the error situation can only be available within the system (here: the HTTP server you send requests to) and if you want to obtain the least filtered information, always go towards the source. Don't look for things, just obtain them.
c.f. Catching exceptions from Guzzle for the version of the Guzzle API you have in use.

Error number 500

I am getting this console error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
And also the content of my site is not visible. Since this is my fist time uploading and playing with these website stuff, I am not able to figure out where my mistake is.
The same thing runs perfectly on my localhost.
Here is the screenshot of the error:
The first error (404) indicates the image URL is not found, make sure you write the image URL properly.
For the second error, refer to this link
as you may have an issue with file permissions or your .htaccess file

NetworkError: 500 Internal Server Error / GET Request turns from black to red in Firebug

Is there a general explanation for the errors that lead to the phenomenon described in the title? Can I make the program tell me the actual cause of these errors?
Assuming you are using PHP backend, HTTP status 500 would mean internal server error - a bug that caused your PHP script to halt. Usually fatal errors cause this.
When you get a 500 error, click on the request in firebug. It would open up all kinds of request data like Headers, Response, Cache, Params etc. Check the response tab once. That might give you a clue about what's wrong in your PHP code.
An HTTP status code of 500 means the error happened on the server side. Firebug only sees what's happening on the client side - i.e. it tells you that the server returned an error code. It doesn't have access to the errors happening on the server side.
I.e. you need to check the log files of your server to see what caused the error. This is normally a fatal error in your server-side script that caused its execution to stop.

file_get_contents() 'failed to open stream' error retrieving tweets

I am trying to create a simple script that will retrieve the last 5 feeds for a twitter user (in this instance the BBC)
It runs okay locally on my development server but once I upload this to a live site I get the following error:
Warning: file_get_contents(https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=bbc&count=5): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in ....
Does anyone know why this doesn't work on my live server (but fine on my dev server?)
As mentioned in file_get_contents throws 400 Bad Request error PHP, you may be better using curl instead of file_get_contents due to its improved error handling - this may provide you with another clue.

Getting data from wikisource.org site

I am trying to get postal codes from this site:
http://pl.wikisource.org/wiki/Lista_kod%C3%B3w_pocztowych_w_Polsce
My code is simple:
<?php
$postalCode = $_GET['code'];
$httpAddr = 'http://pl.wikisource.org/wiki/Lista_kod%C3%B3w_pocztowych_w_Polsce/Okr%C4%99g_'.$postalCode[0].'_'.$postalCode[0].$postalCode[1].'-xxx';
file_get_contents($httpAddr);
?>
But when i set $postalCode to 03-000 (also 01-000, 05-000, but for 07-000, 61-000, 62-000 is working) i am reciving error:
Warning: file_get_contents(http://pl.wikisource.org/wiki/Lista_kod%C3%B3w_pocztowych_w_Polsce/Okr%C4%99g_0_03-xxx): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /var/www/clients/client1/web4/web/ofix/test.php on line 5
Page address is correct, you can copy and past it in your web browser and it works.
Any ideas?
As Lightness Races in Orbit suspected, it does seem that the webserver is blocking PHP's request.
Using cURL instead of file_get_contents() reveals the details:
HTTP/1.0 403 Forbidden
Scripts should use an informative User-Agent string with contact information, or they may be IP-blocked without notice.
A web browser sends a valid User-Agent header in its request, which is why the page loads OK in your browser but not in PHP.
In my tests loading this URL in PHP, sometimes it succeeds with an HTTP status code of 200, other times it fails with 403. Notice that the error message says scripts may be blocked (ie. sometimes they may not be blocked).
Edit
See this question for more info: How to get results from the Wikipedia API with PHP?

Categories