我为我的PHP代码设置了一个Cron作业,使其每20分钟运行一次。
但是它每次都会杀死EC2 t2micro实例。这是服务器日志。
请帮助。
ip-172-31-42-52登录:[20332.164336]内存不足:杀死进程1241(java)得分174或牺牲孩子
[20332.192538]已杀死进程1241(java)total-vm:1473180kB,anon-rss:176012kB,file-rss:0kB
[23932.654770]内存不足:杀死进程1131(mysqld)得分71或牺牲孩子
[23932.690310]杀死进程1131(mysqld)total-vm:908644kB,anon-rss:72004kB,file-rss:0kB
[39839.833448]内存不足:杀死进程4616(mysqld)得分68或牺牲孩子
[39839.845119]杀死了进程4616(mysqld)total-vm:908692kB,anon-rss:68816kB,file-rss:0kB
[39839.901289]内存不足:杀死进程4646(mysqld)得分69或牺牲孩子
[39839.937446]已杀死进程4646(mysqld)total-vm:908692kB,anon-rss:70392kB,file-rss:0kB
[63862.861894]内存不足:杀死进程6802(mysqld)得分66或牺牲孩子
[63862.875681]终止进程6802(mysqld)total-vm:908176kB,anon-rss:66820kB,file-rss:0kB
[134458.272131] end_request:I / O错误,开发xvda,扇区627665
[134458.288710] end_request:I / O错误,开发xvda,扇区627681
[134458.298582] end_request:I / O错误,开发xvda,扇区5577385
[134458.301842] end_request:I / O错误,开发xvda,扇区5577401
[134458.302578] end_request:I / O错误,开发xvda,扇区5577425
[134458.302578] end_request:I / O错误,开发xvda,扇区5544705
[134458.302578] end_request:I / O错误,开发xvda,扇区1890769
[134458.302578] end_request:I / O错误,开发xvda,扇区1889537
[134458.302578] end_request:I / O错误,开发xvda,扇区1889601
[134458.302578] end_request:I / O错误,开发xvda,扇区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 ";
?>
最佳答案
是否有可能永远不会退出while循环的“ standard_resolution”?如果$CUR_IMG
为TRUE,则$i
永远不会递增。因此它将永远停留在该循环中!