locked
[php] Error 500 with file_get_contents RRS feed

  • 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

    Thursday, February 1, 2018 10:20 PM

Answers

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.

    Friday, February 2, 2018 5:12 AM
  • 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:

    <?php
    ...
     $template = file_get_contents("template.xml");
    ...
    ?>

    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. 

    HEAD https://example.com/https://example.com 

    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:/?$ ?

    Thank you very much


    • Edited by cansado293 Sunday, February 4, 2018 1:41 PM
    Sunday, February 4, 2018 1:39 PM
  • Cansado, have you had any luck with this?

    Thanks!


    Ed Price, Azure Development Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Friday, March 2, 2018 8:39 PM
  • Hi Ed,

    No I don’t understand what I should do, because the same file that launchs error, seconds later php can get it correctly. So, I don’t know the reason and solution in order to read local files. If you have some idea, I’m happy to listen them.

    Thank you

    Friday, March 2, 2018 9:04 PM