[英]file_get_contents not working on CentOS 7
我在phpoffice
中使用了phpoffice
模板處理功能,它適用於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
。
你可以試一試。 希望它能幫助你。
$url= 'https://example.com';
$arrContextOptions=array(
'http' => array(
'method'=>"GET",
'header'=>"Content-Type: text/html; charset=utf-8"
) ,
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
"allow_self_signed" => true, // or "allow_self_signed" => false,
),
);
$response = file_get_contents($url, false, stream_context_create($arrContextOptions));
您可以在 php 手冊https://www.php.net/manual/en/function.file-get-contents.php上閱讀有關 stramContext 的所有手冊
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.