gpt4 book ai didi

php - Cron Jobs 在运行时滞后于我的网站

转载 作者:行者123 更新时间:2023-11-29 01:05:45 24 4
gpt4 key购买 nike

<分区>

对于我的网站,我每 30 分钟运行一次 Cron 作业,如果我尝试在这 30 分钟标记访问我的网站,我要么会收到 500 内部服务器错误,要么会收到 5-10 秒的任何页面加载时间地点。

我正在使用 Php,我的 cron 作业正在使用 Php 和 MySQL。

我如何才能让它不滞后于我的整个网站或使其更快以减少滞后?

克隆:enter image description here

每 15 分钟运行一次的 cron 之一:

<?php
require('functions.php');

global $mysqli;

$select = $mysqli->prepare("SELECT `tkn` FROM `users` ORDER BY `dt` ASC LIMIT 0, 200");
$select->execute();
$select->bind_result($cur_token);

$tokens = array();

while($select->fetch())
{
array_push($tokens, $cur_token);
}

foreach($tokens as $token)
{
$api = Class::Instance($token);
$info = $api->Users->Info();

if(empty($info->error))
{
$info->data->token = $token;
updateUser($info->data);

} else if($info->error->code == 400) {
$update = $mysqli->prepare("UPDATE `users` SET `active` = 0 WHERE `tkn` = ?");
$update->bind_param('s', $token);
$update->execute();
}
}

?>

其他 Cron 作业:

<?php
require('functions.php');

global $mysqli;

$select = $mysqli->prepare("SELECT `email`, `username`, `id` FROM `users` WHERE `email` IS NOT NULL AND `email` <> '' AND `credits` < `credits_offered` AND `emailed_credits` = 0");
$select->execute();
$select->bind_result($email, $username, $id);

$users = array();

while($select->fetch())
{
$users[] = array("id" => $id, "email" => $email, "username" => $username);
}

foreach($users as $user)
{
$to = $user['email'];
$subject = '';
$message = "";
$headers = 'From: email@domain.com' . "\r\n" .
'Reply-To: reply@domain.com';

mail($to, $subject, $message, $headers);

$update = $mysqli->prepare("UPDATE `users` SET `emailed` = 1 WHERE `id` = ?");
$update->bind_param('i', &$user['id']);

$update->execute();
$update->close();
}


?>

我怎样才能减少这些延迟或根本不延迟?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com