In my wordpress website I have to call a PHP function after some interval from a javascript function. Some times it works fine. But some time throws 502 error code. Can you please explain why this type of error throws ? And how can I fix this error ? My javascript function :
function set_online_user(){
clearInterval(setOnlineUser);
if(setUserOnline == true)
{
setUserOnline = false;
jQuery.ajax({
type: 'POST',
url: WQChat.ajaxurl,
data: ({action : 'my_action_set_user_online'}),
success: function(response) {
print_in_console("set_online_user"+response);
setUserOnline = true;
setOnlineUser = setInterval(function(){ set_online_user(); }, 1000);
},
statusCode: {
502: function (error) {
console.log(error);
}
}
});
}
}
var setOnlineUser = setInterval(function(){ set_online_user(); }, 1000);
And my PHP function is :
function my_action_set_user_online()
{
global $wpdb;
$currentUserId = get_current_user_id();
$time = current_time( $type = 'timestamp', $gmt = 1 );
if($currentUserId)
{
update_user_meta( $currentUserId, 'last_login_on', $time);
}
if (time_nanosleep(0, 50000000) === true) {
echo $currentUserId;
}
die();
}
Thanks in advance..