如何防止php加载未请求的页面
我有一个php页面可以很好地执行shellscripts,直到我添加了一个curl进程,现在,页面不再加载最终结果print$output;加载curl请求的页面,是否有方法阻止此页面的加载并恢复原始行为 这是我的php代码:如何防止php加载未请求的页面,php,shell,curl,Php,Shell,Curl,我有一个php页面可以很好地执行shellscripts,直到我添加了一个curl进程,现在,页面不再加载最终结果print$output;加载curl请求的页面,是否有方法阻止此页面的加载并恢复原始行为 这是我的php代码: <?php $thetext = $_POST['thetext']; //unify orthography with NMT //system("curl --data-urlencode 'contents=$thetext' http://www.chan
<?php
$thetext = $_POST['thetext'];
//unify orthography with NMT
//system("curl --data-urlencode 'contents=$thetext' http://www.chandia.net:8080/NMT");
//new code
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www.chandia.net:8080/NMT',
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'contents' => $thetext
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
//tokenize the textarea
system("cat ../NMT/nmt.txt | /opt/foma/linux64/flookup -i -x -w '' /srv/web/dungupeyem/tokenizer.fst > upfiles/thetext.tok");
//analyze the tokenized file
system("cat upfiles/thetext.tok | /opt/foma/linux64/flookup -s ' ==> ' -I f -I 1024k /srv/web/dungupeyem/dungupeyem.fst > upfiles/thetext.all");
//prepare text to output screen
system("grep '==> [^?+]' upfiles/thetext.all > upfiles/thetext.dpy");
system("sed -i 's/$/<br>/g' upfiles/thetext.dpy");
$output = file_get_contents("upfiles/thetext.dpy");
print $output;
?>
提前感谢抱歉,感谢@mogosselin,我将代码从shellscript更改为php函数,最后它运行得非常好,正确的代码如下:
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www.chandia.net:8080/NMT',
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'contents' => $thetext
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
那你为什么要使用curl呢?因为统一过程是在另一个应用程序中运行的,在8080端口的cherrypy下,有没有其他的方法呢?我不是专家,如果你能给我一个更好的建议,我会跟着你的…也许试着用php而不是Shell来实现卷曲这里有一个例子:Karl在说什么。。。。