gpt4 book ai didi

PHP 代码每次运行都会导致 EC2 宕机

转载 作者:行者123 更新时间:2023-11-29 07:34:57 29 4
gpt4 key购买 nike

我已经为我的 PHP 代码设置了一个 Cron 作业,每 20 分钟运行一次。但它每次都会杀死 EC2 t2micro 实例。这是服务器日志。请帮忙。

ip-172-31-42-52 login: [20332.164336] Out of memory: Kill process 1241 (java) score 174 or sacrifice child
[20332.192538] Killed process 1241 (java) total-vm:1473180kB, anon-rss:176012kB, file-rss:0kB
[23932.654770] Out of memory: Kill process 1131 (mysqld) score 71 or sacrifice child
[23932.690310] Killed process 1131 (mysqld) total-vm:908644kB, anon-rss:72004kB, file-rss:0kB
[39839.833448] Out of memory: Kill process 4616 (mysqld) score 68 or sacrifice child
[39839.845119] Killed process 4616 (mysqld) total-vm:908692kB, anon-rss:68816kB, file-rss:0kB
[39839.901289] Out of memory: Kill process 4646 (mysqld) score 69 or sacrifice child
[39839.937446] Killed process 4646 (mysqld) total-vm:908692kB, anon-rss:70392kB, file-rss:0kB
[63862.861894] Out of memory: Kill process 6802 (mysqld) score 66 or sacrifice child
[63862.875681] Killed process 6802 (mysqld) total-vm:908176kB, anon-rss:66820kB, file-rss:0kB
[134458.272131] end_request: I/O error, dev xvda, sector 627665
[134458.288710] end_request: I/O error, dev xvda, sector 627681
[134458.298582] end_request: I/O error, dev xvda, sector 5577385
[134458.301842] end_request: I/O error, dev xvda, sector 5577401
[134458.302578] end_request: I/O error, dev xvda, sector 5577425
[134458.302578] end_request: I/O error, dev xvda, sector 5544705
[134458.302578] end_request: I/O error, dev xvda, sector 1890769
[134458.302578] end_request: I/O error, dev xvda, sector 1889537
[134458.302578] end_request: I/O error, dev xvda, sector 1889601
[134458.302578] end_request: I/O error, dev xvda, sector 1889657

这是 PHP 代码

<?php

$cf = dirname(__FILE__);
if ($cf) chdir($cf);

include_once('/var/www/html/clubberi.com/includes/incl.php');
$conn = ConnectToDatabese();
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

include_once('/var/www/html/clubberi.com/adm/cklog.php');

include_once('/var/www/html/clubberi.com/cls/trights.php');
global $rights;
$rights = new TRights();
$rights->conn = $conn;
$rights->Init();

$update_gallery="INSERT INTO GALLERY (NAZ,SCIMG,SCHEDULE,IUSER) VALUES ";

$sql="SELECT ID,NAZ,INSTA_LINK FROM PLACE WHERE INSTA_LINK<>'' AND GENRE=416";
$rs=$conn->Execute($sql) or die("Ошибка выполнения $sql");

set_time_limit(240);
$i=0;
$link = "";
while(!$rs->EOF)
{
$SCHEDULE = GetFieldFromSQL($conn,"SELECT ID FROM SCHEDULE WHERE DATE(ACTIONTIME)=CURDATE() AND PLACE=".$rs->fields['ID'] ,0);
if(!$SCHEDULE){
$MAX_SC_ID = GetFieldFromSQL($conn,"SELECT MAX(ID) FROM SCHEDULE" ,0);
$curid = $MAX_SC_ID+1;
$nos = NewObject($conn,'TSchedule',$curid);
$nos->sf('NAZ','Some party - '.date('d.m.Y'));
$nos->sf('PLACE',$rs->fields['ID']);
$nos->sf('ACTIONTIME',date('d.m.Y'));
$s = $nos->BaseInsert();
$SCHEDULE = $nos->id;
}
$jsonurl = "https://api.instagram.com/v1/locations/".$rs->fields['INSTA_LINK']."/media/recent?client_id=421b46699e074734932d59771fcd1daf";
#echo $jsonurl;
$newUrl = htmlspecialchars_decode($jsonurl);
$json = file_get_contents($newUrl, 0, null, null);
#print_r("<br>".strlen($json));
$json_output = json_decode($json, true);

while(isset($json_output['data'][$i]['images']['standard_resolution']))
{
$CUR_IMG = GetFieldFromSQL($conn,"SELECT ID FROM GALLERY WHERE SCIMG=".sqlstr($json_output['data'][$i]['images']['standard_resolution']['url']) ,0);
if(!$CUR_IMG)
{
$update_gallery.="('image-".$i."',".sqlstr(hsc($json_output['data'][$i]['images']['standard_resolution']['url'])).",".$SCHEDULE.",".sqlstr($json_output['data'][0]['caption']['from']['id'])."),";
$i++;
}
}
$rs->MoveNext();
}

if($i){
$update_gallery = substr($update_gallery, 0, (strlen($update_gallery)-1));
$rs=$conn->Execute($update_gallery) or die("Ошибка выполнения $update_gallery");
echo $i."images";
}else echo "no image ";

?>

最佳答案

是否有可能它永远不会脱离“standard_resolution”while 循环?如果 $CUR_IMG 为 TRUE,则 $i 永远不会递增。所以它会永远留在那个循环中!

关于PHP 代码每次运行都会导致 EC2 宕机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31161415/

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