douzhi1879 2018-10-19 22:26
浏览 95
已采纳

PHP长时间运行脚本超时

I am creating a page that executes a shell script on a remote server to scan a website and outputs the results on the screen. The output can sometimes take awhile to get depending on the size of the site being scanned. Currently the script works and does what it's supposed to but the problem is when I scan larger sites it stalls and on the platform the website is being hosted on has a timeout of 30 seconds that I cannot alter.

I am wondering what the best way to keep the connection alive whether it just be sending dots to the screen or maybe something else just to keep the connection alive.

Here is my script

$ssh = new Net_SSH2('hostname');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

$ansi = new File_ANSI();
$ssh->enablePTY();
$ssh->setTimeout(60);
$ssh->exec("./test.sh | awk 'NR >= 16 {print}'
");
$ansi->appendString($ssh->read());
echo $ansi->getHistory();

Any help or guidance is deeply appreciated.

  • 写回答

3条回答 默认 最新

  • douzi2749 2018-10-19 22:43
    关注

    You should rather let the page load and e.g. run an AJAX request that will wait for a reply/listen on a port than trying to keep the connection alive.

    So on the user's side, it would run an ajax request (javascript) to the php url, then on success you display the result.

    $.ajax({
      url: "/thescript.php":,
      type: "POST",
      datatype: "POST"
      success: function(){
        //do display stuff
      }
    
    });
    

    Would probably add a reasonable timeout.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题