dsaff82024 2015-07-01 12:31
浏览 53
已采纳

PHP代码每次运行时都会降低EC2

I've set up a Cron job for my PHP code to run every 20 minutes. But it kills the EC2 t2micro instance every time. Here is the server log. Pls help.

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

And here is the PHP code

<?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 ";

?>
  • 写回答

1条回答 默认 最新

  • douguiyan9164 2015-07-01 12:39
    关注

    Is there a chance that it's never getting out of the "standard_resolution" while loop? If $CUR_IMG is TRUE, $i is never incremented. So it'll stay in that loop.. forever!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?