当php下载文件时,使用代理隐藏cloudflare背后的web服务器ip地址

We are running a website behind cloudflare. The website includes community boards (using XenForo engine). I don't want to reveal real website IP, so I moved mail server to a different server/ip and disabled any functionality that can reveal real server IP address (such as option to upload images to server directly from url).

However, right now we are moving our website to https, and we have to cache all user images and avatars on our server before we show it in html.

So, my question is: Is there any general way to set proxy in php configuration and force php to use this proxy when it's downloading files from url (or making any other connection) using file_get_contents, curl etc?

I know that I can review and rewrite all classes/functions that are using curl and/or file_get_contents, but I am looking for universal solution.