我已经为杂志公司建立了一个注册流程的应用程序。该应用程序特别适用于通过条带支付每月订阅的订阅者。
注册过程如下:
使用POST执行Ajax,并将用户详细信息发送到远程服务器上名为registration_processing.php的php页面。
我首先检查应用数据库中是否已存在电子邮件地址
如果电子邮件不存在,那么我会对杂志公司的条带帐户进行API调用,以获取其订阅者电子邮件地址的列表。 (三是大约700,所以我使用分页。)
我根据从条带收到的订阅者电子邮件列表检查使用ajax发布请求发送的电子邮件。
如果匹配,则将用户详细信息存储到应用数据库中,并将用户带到应用的主页。
当我在启动应用程序之前测试它时,这非常有效。
但是,当应用程序启动时,多个用户开始完成此注册过程,现在发生以下情况:
他们的订阅者电子邮件地址成功匹配,他们的详细信息存储在app数据库中,但是ajax调用正在执行错误功能,错误消息" Gateway超时"。在测试时,它需要大约32秒才能发生超时。 对此远程服务器的所有其他ajax请求都正常工作。 我查看了phpinfo.php,我注意到" max_execution_time"是120.我不确定这是否与任何事情有关。我需要增加这个吗? 谢谢你的帮助。
//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
registration_processing.php(这是验证之后的主要部分)
//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.
}