简体   繁体   English

防止有角度的 http post 请求超时

[英]Prevent angular http post request timeout

I am created a AngularJs Post request.The request contain a long process take more than 2 minutes for perform that.But my angular request return null error after 15 seconds.request perfectly working and no error.But angular request time out with in 15 seconds我创建了一个 AngularJs Post 请求。请求包含一个很长的过程,执行该过程需要超过 2 分钟。但是我的角度请求在 15 秒后返回空错误。请求完美工作并且没有错误。但是角度请求在 15 秒内超时

 $http.post('/api/evaluateOmrExamination',{exam_id:$scope.curExam.id})
            .success(function(data,status,headers,config){
                $scope.showProgress=false;
                ngNotify.config({
                    theme: 'pure',
                    position: 'top',
                    duration: 3000,
                    type: 'info',
                    sticky: false,
                    button: true,
                    html: false
                });

                ngNotify.set('Evaluate Examination Completed Successfully');

                $scope.errorLists=data;
            }).error(function(data,status,headers,config){
                console.log(data);
                //$scope.showProgress=false;
            });

I am also set time out in angular but no use.我也设置了角度超时但没有用。

 app.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.timeout = 10000000;
 }]);

I need your suggestions我需要你的建议

Short term fix is to increase your server's timeout (this is not a client / Angular issue).短期修复是增加服务器的超时(这不是客户端 / Angular 问题)。 You say you're using LAMP, so you must configure PHP's max_execution_time property in php.ini to a larger value.您说您使用的是 LAMP,因此您必须在 php.ini 中将 PHP 的max_execution_time属性配置为更大的值。 You may also need to configure Apache's timeout in httpd.conf.您可能还需要在 httpd.conf 中配置 Apache 的超时。

Long term fix, the request could return immediately (ie not 2 minutes or even 15 seconds later).长期修复,请求可以立即返回(即不是 2 分钟甚至 15 秒后)。 This doesn't mean the job is done, just that the request to perform the job is done.这并不意味着工作已经完成,只是执行工作的请求已经完成。 Then you can ping your server every X seconds to see if the job is complete, and then get the data to display to the user.然后你可以每隔 X 秒 ping 你的服务器,看看作业是否完成,然后获取数据显示给用户。 It seems like more work, and it may take a little more time, but I've found that it can be easier to develop and debug this way instead of having single monolithic requests that do a lot of work.这似乎需要更多的工作,而且可能需要更多的时间,但我发现以这种方式进行开发和调试会更容易,而不是让单个单一请求完成大量工作。 In addition to being a better user experience :)除了提供更好的用户体验之外:)

There are some good recommendations here .有一些好的建议在这里

app.factory('timeoutHttpIntercept', function ($rootScope, $q) {
    return {
        'request': function(config) {
            config.timeout = 10000000;
            return config;
         }
    };
});

And in your config:在你的配置中:

$httpProvider.interceptors.push('timeoutHttpIntercept');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM