我在phpofficeLaravel 中使用模板处理功能,它在Ubuntu,Windows和Mac. 当我迁移到centos服务器时,该功能停止工作。我发现 phpoffice 正在调用file_get_contents以打开模板文件,但它失败了。
于是开始测试 file_get_contents 函数。
echo file_get_contents('http://my-server-ip-address/api/public/storage/templates/template.docx');
错误,
ErrorException (E_WARNING)
file_get_contents(http://my-server-ip-address/api/public/storage/templates/template.docx): failed to open stream: Connection timed out
php.ini 配置,
allow_url_fopen = On // tried allow_url_fopen = 1 also
试过了,
user_agent = "PHP"
我无法将函数调用更改为CURL方法,因为这是在 phpoffice composer 包中内部处理的。有解决方案吗?
我可以直接在浏览器上访问该文件。没有问题。
编辑:
echo file_get_contents('http://my-ip/api/public/storage/templates/template.docx');echo file_get_contents('http://my-domain/api/public/storage/templates/template.docx');echo file_get_contents('https://www.google.com/');echo file_get_contents('http://localhost/api/public/storage/templates/template.docx');
这里 1 和 2 不能在 IP/域指向的同一台服务器上工作,但它可以在包括本地在内的任何其他系统上工作。
概括
wget和相同的问题CURL。
服务器无法使用 IP 或域找到自己,但其他系统可以与服务器通信。
服务器仅将自身标识为localhost。