Я пытаюсь использовать curl для запуска локального php-файла на моем общем сервере centOs7, но я не могу использовать метод curl для своих локальных файлов.вот мои файлы примеров:
--bg/
------back.php
------curl.php
вот коды curl.php:
<?php
function run_curl($data){
//url-ify the data for the POST
$fields_string = '';
//foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = http_build_query($data);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
//curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: ' . $content_type]);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
)
);
curl_setopt($ch,CURLOPT_URL,'https://taskdan.com/bg/back.php');
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,50); # timeout after 10 seconds, you can increase it
//curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); # Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); # Some server may refuse your request if you dont pass user agent
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//execute post
$result = curl_exec($ch);
//print_r($result);
//print_r((curl_getinfo($ch)));
//error_log($result);
//close connection
curl_close($ch);
return ($result);
}
echo " Output : </br>";
echo run_curl( [
"ab" => "test"
]);
?>
и ниже мои коды back.php:
<?php
header("Content-Type:application/json");
echo json_encode([
"a" => "test"
])
?>
КогдаЯ запускаю этот код, похоже, он преобразует мое доменное имя в публичный IP-адрес сервера.Curl отлично работает за пределами серверных скриптов.
когда я запускаю curl с использованием SSH, я получаю это:
[root@??? ~]# curl https://taskdan.com -k
<html>Apache is functioning normally</html>
[root@??? ~]# curl http://171.22.27.118 -k
<html>Apache is functioning normally</html>
Я хочу запустить некоторые скрипты в фоновом режиме, Есть ли способзапустить локальный php файл с параметрами POST по CURL?