Php file get contents 500 error

Php file get contents 500 error

This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.

Answered by:

Question

Hello, I’m using from 2-3 year app service that has php website and I haven’t had error 500 all time (1 or 2 errors at year) but I’m receiving alerts (20-50 at day) from 20/12/17. I have fixed warnings that I have seen on logs but it continues. The app service is a shared environment and I check the quotes and I think that It doesn’t exceed the limit. I have activated the control of requests where 500 error happened and it works. Errors occur when try to get files, for example, a xml template, png file. Could you help me in order to understand the reason that it can’t read file? Thank you

Answers

You may refer this blog: https://blogs.msdn.microsoft.com/azureossds/2016/09/28/how-to-identifyreview-errors-on-php-applications-in-azure-web-apps-using-log-stream-service/, which describes “How to identify/review PHP errors on Azure Web Apps using Log Stream service”. Also, try to modify and add the below code according to your application and see if it helps,

$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n")); 
$context = stream_context_create($opts); 
$header = file_get_contents('https://www.example.com',false,$context);

—————————————————————————————————— Do click on «Mark as Answer» on the post that helps you, this can be beneficial to other community members.

  • Proposed as answer by Swikruti Bose Friday, February 2, 2018 5:12 AM
  • Marked as answer by Ed Price — MSFT Microsoft employee Friday, March 2, 2018 8:39 PM
Читайте также:  Html meta name search

All replies

You may refer this blog: https://blogs.msdn.microsoft.com/azureossds/2016/09/28/how-to-identifyreview-errors-on-php-applications-in-azure-web-apps-using-log-stream-service/, which describes “How to identify/review PHP errors on Azure Web Apps using Log Stream service”. Also, try to modify and add the below code according to your application and see if it helps,

$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n")); 
$context = stream_context_create($opts); 
$header = file_get_contents('https://www.example.com',false,$context);

—————————————————————————————————— Do click on «Mark as Answer» on the post that helps you, this can be beneficial to other community members.

  • Proposed as answer by Swikruti Bose Friday, February 2, 2018 5:12 AM
  • Marked as answer by Ed Price — MSFT Microsoft employee Friday, March 2, 2018 8:39 PM

Hello Swikruti, Thank you by your answer, it is very usefull. I have been able to find two problems. the first is About file_get_contents that are local files, a simple of my code is this:

And then it sometimes launchs error that php hasn’t permissions to access to the file template.xml or other files. The log said me this:

Most likely causes:

  • IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
  • IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
  • IIS was not able to process configuration for the Web site or application.
  • The authenticated user does not have permission to use this DLL.
  • The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.
Читайте также:  Extracting substrings in python

when I deployed for first time I didn’t see any web.config file. Does it require one? if the answer is yes, Could you say me a sample? I have checked the sample php of azure and I can find only php files.

And the second problem is some user or machine is calling a bad url.

it hasn’t logic. With .htaccess I know that I can redirect for example «/folder/» with this line: RedirectMatch 403 ^/folder/?$ But How could I redirect it? does it work with ^/https:/?$ ?

Источник

Php file get contents 500 error

Gray Pipe

This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.

Answered by:

Question

Hello, I’m using from 2-3 year app service that has php website and I haven’t had error 500 all time (1 or 2 errors at year) but I’m receiving alerts (20-50 at day) from 20/12/17. I have fixed warnings that I have seen on logs but it continues. The app service is a shared environment and I check the quotes and I think that It doesn’t exceed the limit. I have activated the control of requests where 500 error happened and it works. Errors occur when try to get files, for example, a xml template, png file. Could you help me in order to understand the reason that it can’t read file? Thank you

Answers

You may refer this blog: https://blogs.msdn.microsoft.com/azureossds/2016/09/28/how-to-identifyreview-errors-on-php-applications-in-azure-web-apps-using-log-stream-service/, which describes “How to identify/review PHP errors on Azure Web Apps using Log Stream service”. Also, try to modify and add the below code according to your application and see if it helps,

$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n")); 
$context = stream_context_create($opts); 
$header = file_get_contents('https://www.example.com',false,$context);

—————————————————————————————————— Do click on «Mark as Answer» on the post that helps you, this can be beneficial to other community members.

  • Proposed as answer by Swikruti Bose Friday, February 2, 2018 5:12 AM
  • Marked as answer by Ed Price — MSFT Microsoft employee Friday, March 2, 2018 8:39 PM

All replies

You may refer this blog: https://blogs.msdn.microsoft.com/azureossds/2016/09/28/how-to-identifyreview-errors-on-php-applications-in-azure-web-apps-using-log-stream-service/, which describes “How to identify/review PHP errors on Azure Web Apps using Log Stream service”. Also, try to modify and add the below code according to your application and see if it helps,

$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n")); 
$context = stream_context_create($opts); 
$header = file_get_contents('https://www.example.com',false,$context);

—————————————————————————————————— Do click on «Mark as Answer» on the post that helps you, this can be beneficial to other community members.

  • Proposed as answer by Swikruti Bose Friday, February 2, 2018 5:12 AM
  • Marked as answer by Ed Price — MSFT Microsoft employee Friday, March 2, 2018 8:39 PM

Hello Swikruti, Thank you by your answer, it is very usefull. I have been able to find two problems. the first is About file_get_contents that are local files, a simple of my code is this:

And then it sometimes launchs error that php hasn’t permissions to access to the file template.xml or other files. The log said me this:

Most likely causes:

  • IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
  • IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
  • IIS was not able to process configuration for the Web site or application.
  • The authenticated user does not have permission to use this DLL.
  • The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

when I deployed for first time I didn’t see any web.config file. Does it require one? if the answer is yes, Could you say me a sample? I have checked the sample php of azure and I can find only php files.

And the second problem is some user or machine is calling a bad url.

it hasn’t logic. With .htaccess I know that I can redirect for example «/folder/» with this line: RedirectMatch 403 ^/folder/?$ But How could I redirect it? does it work with ^/https:/?$ ?

Источник

Php – file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 500 Internal > Server Error in

I see many questions matching to my issue. But none of them is providing any workable solution. so instead of making complex functionality i need simple solution. Please I dont’ want cURL. I’ve already done a lot with this code.

I’m working on a scraping project and need to load the contents of product revisions from ebay.

Here is the URL i’m troubling with.

https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&item=272908801183 

this file_get_contents(); is working perfectly fine on different URLs but don’t know why not on this.

This is the code i’m using.

but i’m getting this error..

Warning:
file_get_contents(https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&&item=272908801183):
failed to open stream: HTTP request failed! HTTP/1.1 500 Internal
Server Error in
/Users/samz/Documents/projects/scraping/test.php
on line 3

Best Solution

file_get_contents (read the tip on blue rectangle) can be easily blocked on server side through php.ini avoid using it. When you want to get data from an other site use curl instead. http://php.net/manual/en/book.curl.php, there are plenty of options that you can use with curl, by playing a bit the following code can work with your url.

$ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_URL,"https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&item=272908801183"); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13"); $data = curl_exec($ch); curl_close($ch); 

and by echoing the $data varible you can see the whole page.

you can try parsing the data from the page by utilizing php DOM Methods and convert them to the data type you want (object class, array etc).

Php – file_get_contents – failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

I’ve had this problem too, when I working on a little test server at home. The domain name is resolved to your external IP address, and a request is sent. But because the request is coming from inside your network, the router doesn’t recognise it as a normal request. It probably has a web interface for configuring it, and tries to return a page from its own management system, which is then not found at the path you specified.

In that case, I was working on a Windows PC, and I could solve it by adding the domain I was testing to my hosts file, specifying 127.0.0.1 as the IP-address (or the IP-address of the server, if it is another machine within the same network). In Linux there should be a similar solution, I think.

The problem isn’t PHP or your server, but your router.

Php – Why I’m getting 500 error when using file_get_contents(), but works in a browser
$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n")); $context = stream_context_create($opts); $header = file_get_contents('https://www.example.com',false,$context); 

If this doesn’t work, maybe you cant read from https?

Источник

Оцените статью