I was using phpoffice
template processing functionality with Laravel and it worked on Ubuntu
, Windows
and Mac
. The functionality stopped working when I migrated to centos
server. I figured out that the phpoffice was calling file_get_contents
to open the template file and it is failing.
So started testing the file_get_contents function.
echo file_get_contents('http://my-server-ip-address/api/public/storage/templates/template.docx');
Error,
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 configuration,
allow_url_fopen = On // tried allow_url_fopen = 1 also
Tried,
user_agent = "PHP"
I cannot change the function call to CURL
approach as this is internally handled in the phpoffice composer package. Is there a solution for this?
I can access the file directly on the browser. No issues with that.
Edit:
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');
Here 1 & 2 not working from the same server which the IP/domain points to but it works from any other systems including local.
Summary
Same issue with wget
and CURL
.
The server can't find itself using IP or domain but other systems can communicate with server.
The server identifies itself only as localhost
.