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

前端 未结 3 1922
既然无缘
既然无缘 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: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.

提交回复
热议问题