【问题标题】:How to prevent php of loading a not requested page如何防止 php 加载未请求的页面
【发布时间】:2014-06-24 15:37:58
【问题描述】:

在我添加 curl 进程之前,我有一个很好地执行 shellscripts 的 php 页面,现在,页面而不是加载最终结果 (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;
?>

提前致谢

【问题讨论】:

  • 那你为什么要使用 curl?
  • 因为统一进程是在另一个应用程序上运行在8080端口的cherrypy下,还有其他方法吗?我不是专家,如果你能提出更好的方法,我会跟着你....
  • 也许尝试在 php 中而不是从 shell 中卷曲
  • 这是一个例子:codular.com/curl-with-php Karl 正在谈论的内容。
  • 我尝试使用来自 php (hayageek.com/php-curl-post-get) 的 curl,但它发生了同样的情况....

标签: php shell curl


【解决方案1】:

抱歉,感谢@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);

【讨论】:

    猜你喜欢
    • 2022-07-06
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    相关资源
    最近更新 更多