我有一个非常好的执行shellcripts的php页面,直到我添加了一个curl进程,现在,页面而不是加载最终结果(print $ output;)加载curl请求的页面,有没有办法阻止这个加载页面并恢复原来的行为?
这是我的PHP代码:
<?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;
?>
提前致谢
答案 0 :(得分:0)
很抱歉,感谢@mogosselin我已经将代码从shell脚本更改为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);