如何在Mac终端上通过curl访问php URL

Pan*_*yar 2 php terminal

我有一个托管在某个服务器上的 php 文件,现在我想通过curl 访问 URL 的输出,如下所示:

curl -s  http://ankur.serve.qa.vdopia.com/getTag.php?type=vanilla&tag=master
[1] 81246
**vanilla4.9.8-2**
Run Code Online (Sandbox Code Playgroud)

我得到了很多东西,但实际的输出是 vanilla4.9.8-2 来得有点晚,当我在输入curl命令后按下回车键时,它只会向我显示进程ID并进入后台。如何在不后台执行命令的情况下获得输出。

这是php的完整代码:

header('Content-type: text/plain');

$type = $_GET['type'];
$tag = $_GET['tag'];

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if($type=='portal')
{
    if($tag=='' || $tag=='master')
    {
        curl_setopt($ch, CURLOPT_URL, 'http://portal.vdopia.com/version.txt?'.uniqid());  
        $output = curl_exec($ch);  
        curl_close($ch); 

        echo $output;
    }
}
else if ($type=='vanilla')
{
    if($tag=='' || $tag=='master')
    {
        echo 'checking';
        curl_setopt($ch, CURLOPT_URL, 'http://serve.vdopia.com/version.txt?'.uniqid());  
        $output = curl_exec($ch);  
        curl_close($ch); 

        echo $output;
    }
}

exit();
Run Code Online (Sandbox Code Playgroud)

Jan*_*art 5

你的curl命令中的&会将curl(或任何shell命令)发送到后台。您需要转义&来删除 shell 的这种特殊含义。只需像这样执行命令就可以解决问题:

curl -s 'http://ankur.serve.qa.vdopia.com/getTag.php?type=vanilla&tag=master'
Run Code Online (Sandbox Code Playgroud)

输出:

vanilla4.9.8-21
Run Code Online (Sandbox Code Playgroud)