Php Ajax错误函数正在执行,错误消息为;“网关超时”;当多个用户完成注册过程时

Php Ajax错误函数正在执行,错误消息为;“网关超时”;当多个用户完成注册过程时,php,ajax,timeout,stripe-payments,Php,Ajax,Timeout,Stripe Payments,我已经为一家杂志公司开发了一个带有注册流程的应用程序。该应用特别适用于通过stripe每月付费的用户 登记程序如下: 用户在应用程序中输入姓名、电子邮件和密码(两次) Ajax通过POST执行,用户详细信息发送到远程服务器上名为registration_processing.php的php页面 我首先检查应用程序数据库中是否已经存在电子邮件地址 如果该电子邮件不存在,那么我会对该杂志公司的stripe帐户进行API调用,以获取其订阅者电子邮件地址列表。(三个大约是700,所以我使用分页。) 我将

我已经为一家杂志公司开发了一个带有注册流程的应用程序。该应用特别适用于通过stripe每月付费的用户

登记程序如下:

  • 用户在应用程序中输入姓名、电子邮件和密码(两次)
  • Ajax通过POST执行,用户详细信息发送到远程服务器上名为registration_processing.php的php页面

  • 我首先检查应用程序数据库中是否已经存在电子邮件地址

  • 如果该电子邮件不存在,那么我会对该杂志公司的stripe帐户进行API调用,以获取其订阅者电子邮件地址列表。(三个大约是700,所以我使用分页。)

  • 我将通过ajax post请求发送的电子邮件与从stripe收到的订户电子邮件列表进行核对

  • 如果存在匹配项,则我将用户详细信息存储到应用程序数据库中,并将用户带到应用程序的主页

  • 在启动应用程序之前,我对它进行了测试,结果非常理想

    但是,当应用程序启动时,多个用户开始进行此注册过程,现在发生了以下情况:

    他们的订户电子邮件地址已成功匹配,他们的详细信息存储在应用程序数据库中,但ajax调用正在执行错误函数,错误消息为“网关超时”。测试时,超时发生前大约需要32秒。 对该远程服务器的所有其他ajax请求都工作正常。 我查看了phpinfo.php,发现“最大执行时间”是120。我不确定这是否与什么有关。我需要增加这个吗? 谢谢你的帮助

    AJAX代码 条带php函数
    函数getListOfCustomers($stripe){
    $customers_emails=array();
    \Stripe\Stripe::setApiKey($Stripe['secret_key']);
    $customers=\Stripe\Customer::all(数组(“limit”=>100));
    foreach($customers->autoPagingIterator()作为$customer){
    阵列推送($customers\u email,$customer['email']);
    }
    返回$customers\u电子邮件;
    }
    函数checkIfUserIsSubscriber($user\u email\u address,$stripe){
    //将布尔值初始化为false。如果客户存在,它将更改为true,否则将保持false。
    $userIsSubscriber=false;
    $array\u of_customers=getListOfCustomers($stripe);
    对于($x=0;$x
    很难找出问题所在,504超时取决于多个因素,服务器本身的速度,可能您与sql server的连接的cpu负载很高,或者您与Stripe的连接过长time@hassan我怀疑这与从stripe中检索客户有关,因为这确实需要一段时间。因此,在这种情况下,我应该为注册过程执行多个ajax请求,还是可以增加超时长度?如果不跟踪整个问题上下文,很难说,但最好的方法是在尝试尽可能优化代码后,离开这些解决方案(增加超时和多个ajax请求)@哈桑,谢谢。我试过这个初始设置(“最大执行时间”,300);但是,要进行测试,它在32秒后仍然超时。谢谢你的帮助。注意,这是一个简单快捷的解决方案,正如我在之前的评论中提到的,优化总是比增加超时要好
        //this registration email will need to be checked on the server side with the list of subscribers from stripe
            $.ajax({
            url: app_root_url + 'registration_processing.php',
                data: JSON.stringify(params), 
            type: "POST",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
    
                success: function(data){
    
                var result = data;
    
                var exception_occurred = result.exception_occurred; 
                if(exception_occurred){
                    var emailAlreadyExists = result.email_already_exists; 
                    if(emailAlreadyExists){
                        displayError('registration_feedback_message', 'This email already exists in the system. If you already have an account please <a class="inline_link normal_link" href="#page-login">login here!</a>');
    
                    }else{
                        var exception_message = 'Error: ' + result.exception_message;
                        displayError('registration_feedback_message', exception_message);
                    }
                }else{
                    var emailAlreadyExists = result.email_already_exists; 
                    if(emailAlreadyExists){
                        //email already exists in our database and therefore the user is already registered so should use the login form
                        //email already exists. if you already have an account then login here.
    
                            displayError('registration_feedback_message', 'This email already exists in the system. If you already have an account please <a class="inline_link normal_link" href="#page-login">login here!</a>');
    
                    }else{
                        //email does not already exist in our database
                        var userIsSubscriber = result.user_is_subscriber; 
    
                        if(!userIsSubscriber){
                            //this email address does not exist in the subscribers database
    
                        }else{
                            //successful registration. 
                            //user is subscriber and therefore has now been registered 
    
                        }
                    }
                }
    
            }//end success
            ,
                error: function(xhr, status, error) {
                displayError('registration_feedback_message', 'Error message: ' + error);
    
    
            }
        });//end ajax
    
    //check email address exists
                $result = checkEmailExists($email, $pdoConnection);
                if($result['email_exists'] == true){
                    $data['exception_occurred'] = false;
                    $data['email_already_exists'] = true;   
    
                    echo json_encode($data);
    
    
                }else{
    
                    //email doesnt exist yet
    
                    //check if the registration email entered, exists on the subscriber's database. currently their subscribers exist in stripe
                    $subscribersEmailExists = checkIfUserIsSubscriber($email, $GLOBALS['stripe']); 
    
                    if($subscribersEmailExists == 1 || $subscribersEmailExists == true){
                        //if this returns true therefore this user is indeed a subscriber so now register their details on our
                        //app database including password.
    
                        $userPrivilegeID = 1;
                        $userHasPassword = 1;
    
                        $profileImage = "images/profile_images/blank-avatar.png"; //this should come from the html
    
                        $results = registerUser($password, $email, $isAvatarImage, $profileImage, $userPrivilegeID, $display_name, $userHasPassword, $registration_mob_select, $pdoConnection);
    
                        if($results['exception_occurred'] == true){
                            $data['exception_occurred'] = true;
                            $data['exception_message'] = $results['exception_message']; 
                            if(strpos($data['exception_message'], 'Duplicate') !== false){
    
                                //check if the exception is to do with email already existing.                  
                                //SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry for key 'emailAddress'
                                $data['email_already_exists'] = true;   
    
                            }else{
    
                                $data['email_already_exists'] = false;
                            }
                            echo json_encode($data);
    
                        }else{
                            $data['exception_occurred'] = false;
                            if($results['email_already_exists'] == true){
                                //email already exists. user is already registered and therefore has a password
                                //need to show error to user to say they are already registered and should use the login form.
    
                                $data['email_already_exists'] = true;
                                echo json_encode($data);
    
                            }else{
                                $data['email_already_exists'] = false;
    
    
                                echo json_encode($data);
                            }
                        }
    
                    }else{
                        $data['email_already_exists'] = false; //email does not already exist in our database
                        //this email address does not exist in the subscribers database
                        //therefore this user is not a paying subscriber so needs to be redirected to the website in order to subscribe
                        //$subscribersEmailExists will be false here
                        $data['user_is_subscriber'] = false;
    
                        echo json_encode($data);
                    }
                }
    
    function getListOfCustomers($stripe){
        $customers_emails = array();
        \Stripe\Stripe::setApiKey($stripe['secret_key']);
    
        $customers = \Stripe\Customer::all(array("limit" => 100)); 
    
        foreach($customers->autoPagingIterator() as $customer){ 
            array_push($customers_emails, $customer['email']); 
    
        }
        return $customers_emails; 
    
    }
    function checkIfUserIsSubscriber($user_email_address, $stripe){
        //initialize a boolean to false. it will be changed to true if customer exists otherwise will remain false.
        $userIsSubscriber = false;
        $array_of_customers = getListOfCustomers($stripe);
    
        for($x=0; $x < count($array_of_customers); $x++){
            //the users email matches one in the array of customers then assign the boolean to true.
            if($user_email_address == $array_of_customers[$x]){
                $userIsSubscriber = true;
    
            }
        }
        return $userIsSubscriber; //this value will be true or false depending on whether customers email exists in companies stripe account.
    
    }