dpp34603 2012-09-21 15:17
浏览 107
已采纳

500(内部服务器错误)php shell_exec

I am using php shell_exec to run a command from jQuery but it keeps timing out.

So my jquery is as follows.

var send = {
    url: $(this).data('url')
}

$.ajax({
    type: "POST",
    url: "<?php echo base_url(); ?>index.php/upload",
    data: send,
    //dataType: "json",
    //timeout: 8000,
    beforeSend: function() {

    },
    success: function(response) {
        console.log(response);
    },
    error: function () {
        alert('error');
    }
});

This then calls a function which runs shell_exec

function upload(){
    $output = shell_exec("wget {$_POST['url']} 2>&1");      
    echo "<pre>" . $output . "</pre>";
}

Ok this works fine if the url that is posted for wget get is pulling a small file but if wget is getting a file say over 20mb i get 500 (Internal Server Error)

Things i have checked so far all my php setting file upload limit max file size etc memory limit all i have set to the max.

The thing that i dont get is this worked fine locally but on my hosting i get this error, i have contact my hosting media temple and they have said it is out of their scope of support.

Any suggestion on how to debug further?

  • 写回答

1条回答 默认 最新

  • drahywu329376 2012-09-21 15:31
    关注

    What is happening is that some kind of reverse proxy - for example Apache balancer - is timing out, whether the PHP script times out or not. You can verify by creating a script such as

    <?php sleep(60); ?>
    

    and experimenting with different delays.

    Anyway, upping the time limit would only appear to be a solution, since some browsers (e.g. IE8+) will timeout no matter what.

    Usually this is solved by detaching the wget process and having a PHP page checking on the process status with a refresh of, say, 5..30 seconds. But many providers take an understandably dim view of detaching processes, since this might hog the memory of a system serving dozens of websites (=paying customers!). So you'd have to check it out with the provider whether the solution is acceptable.

    If it is, you can check out " Asynchronous shell exec in PHP ".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度