are there mechanisms, to disable file_get_contents() function working?

前端 未结 3 1924
既然无缘
既然无缘 2021-01-03 14:03

i use file_get_contents function to grab data from sites and store the data in database. it will be very inconvenient for me, if one day the script will start not working.

相关标签:
3条回答
  • 2021-01-03 14:12

    It is possible to disable certain functions using disable_function. Furthermore the support of URLs with filesystem functions like file_get_contents can be disabled with allow_url_fopen. So chances are that file_get_contents might not work as expected one day.

    0 讨论(0)
  • 2021-01-03 14:13

    I know, that it can start not working, if they change the structure of site, but now i'm afraid, that maybe there are mechanisms to disable the working of this function, maybe from server?

    Yes, it can be disabled from php.ini with allow_url_fopen option. You have other options such as CURL extension too.

    Note also that you will need to have openssl extension turned on from php.ini if you are going to use the file_get_contents function to read from a secure protocol.

    So in case file_get_contents is/gets disabled, you can go for CURL extension.

    0 讨论(0)
  • 2021-01-03 14:13

    There are at least two PHP configuration directives that can break your script :

    • If allow_url_fopen is disabled, then, file_get_contents() will not be able to fetch files that are not on the local disk
      • i.e. it will not be able to load remote pages via HTTP.
      • Note : I've seen that option disabled quite a few times
    • And, of course, with disable_functions, any PHP function can be disabled.


    Chances are pretty low that file_get_contents() itself will ever get disabled...

    But remote-file loading... Well, it might be wise to add an alternative loading mecanism to your script, that would use curl in case allow_url_fopen is disabled.

    0 讨论(0)
提交回复
热议问题