Fatal error: Out of memory

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Fatal error: Out of memory

Postby Krish307 » 28. May 2015 11:41

Dear Friends,

We have uploaded some files and while sorting and doing validation of the invalid fields, we get the below message

"Fatal error: Out of memory (allocated 1185153024) (tried to allocate 1024 bytes) in D:\xampp\htdocs\datacollation\income\sortdata.php on line 13"

This error varies as per the file and line.

We need to re run the files several times manually for it to give results.

Query During which I get error :

select * from `income_rawdata` where `filename`='$filename' and `validation`=''

Configuration :
OS - Windows Server 2008 64 Bit (with Active Directory Services)
Version - XAMPP Version 5.6.3 installed on D: Drive
RAM - 16 GB
Processor - Xeon

Have also tried by setting the memory_limit to "-1" in the php.ini file.

Kindly advice, stuck badly.

My dead line is already crossed.

Thank You.
Krish307
 
Posts: 2
Joined: 28. May 2015 11:12
Operating System: Windows Server 2008

Re: Fatal error: Out of memory

Postby JJ_Tagy » 28. May 2015 11:49

Guessing because I don't see the code, but maybe you are stuck in a loop with the query?
JJ_Tagy
 
Posts: 788
Joined: 30. January 2012 13:44
XAMPP version: 5.5.15
Operating System: Windows 10 Pro x64

Re: Fatal error: Out of memory

Postby Krish307 » 28. May 2015 12:15

JJ_Tagy wrote:Guessing because I don't see the code, but maybe you are stuck in a loop with the query?


Here is the code :

Code: Select all
$concar=mysqli_connect("localhost","root","","car_db") or die('Unable to connect car_db');

$getfiles=mysqli_query($concar,"SELECT distinct `filename` FROM `car_rawdata` where `validation`=''");

while($rofile=mysqli_fetch_array($getfiles)){

$filename=$rofile['filename'];
//echo '<br/>';
//echo $qs="select * from `car_rawdata` where `filename`='$filename'";
//echo '<br/>';
$query=mysqli_query($concar,"select * from `car_rawdata` where `filename`='$filename' and `validation`=''");
while($row=mysqli_fetch_array($query)){
$mbnum=$row['mobile1'];
$id=$row['id'];

$mbnum = str_replace(' ', '',$mbnum);
$mbnum= preg_replace("/[^a-zA-Z0-9\s]/", "",$mbnum);                                                               
$chhh=strlen(trim($mbnum));
                                                                           
$mobilenum=trim($mbnum);
                                                            if($chhh == '12'){
                                                            $chk=str_replace('"','', $mobilenum);
                                                               $mobilenum=trim($chk);
                                                            }
                                                            elseif($chhh == '10'){
                                                               $mobilenum=trim($mobilenum);
                                                            }
                                                            elseif($chhh == '14'){
                                                                           if(substr($mobilenum, 0, 1)=='"' && substr($mobilenum, 0, 14)=='"')
                                                                           {
                                                               $chk=str_replace('"','',$mobilenum);
                                                               $mobilenum=substr($chk,2,12);
                                                                           }
                                                                           else
                                                                           {
                                                                                          $mobilenum = str_replace(' ', '',$mobilenum);
                                                                            $mobilenum= preg_replace("/[^a-zA-Z0-9\s]/", "",$mobilenum);
                                                                           }
                                                            }
                                                           
                                                                           
                                             //echo"final num--------".$mobilenum;
                                                           
                                                           
                                                            if(preg_match('/[0-9]/', $mobilenum)){
                                                                                           if(strlen(trim($mobilenum))==10){
                                                                                                         
                                                                                                         $mobilenum=$mobilenum;
                                                                                           }//if no is 10digit for e.g.9469183445
                                                                                           
                                                                                           elseif(strlen(trim($mobilenum))==12){
                                                                                                            if(substr($mobilenum, 0, 2)==91){
                                                                                                            $mobilenum=substr($mobilenum,2,10);// remove 91 from mobile number
                                                                                                           
                                                                                                           
                                                                                                            }
                                                                                           }
                                                                                                          elseif(strlen(trim($mobilenum))==11){
                                                                                                            if(substr(trim($mobilenum,0,1))==0){
                                                                                                                       
                                                                                                                       
                                                                                                            $mobilenum=substr($mobilenum,1,10);// remove 91 from mobile number
                                                                                                           
                                                                                                         
                                                                                                           
                                                                                                          }
                                                                                             }//if no is 12digit with 91 for e.g.919469183445
                                                                                             
                                                                                           }//all digit
                                                                                         
                                                                           //echo"final num--------".$mobilenum;
                                                                            $ll=strlen(trim($mobilenum));
                                                                           
                              /**********check all chars are digit only*************/
                              $rere=substr($mobilenum, 0, 1);
                              $validation='';
                              //echo $mobilenum;
                                                                                           if(substr($mobilenum, 0, 1)=='9' or substr($mobilenum, 0, 1)=='8' or substr($mobilenum, 0, 1)=='7'){
                                                                                                         
                                                                                                                         if(strlen($mobilenum)==10)
                                                                                                                         {
                                                                                                                                       $validation='valid';
                                                                                                                         }
                                                                                                                         else
                                                                                                                         {
                                                                                                                                        $validation='invalid';
                                                                                                                         }
                                                                                                            }
                                                                                                            else{
                                                                                                         
                                                                                                                            $validation='invalid';
                                                                                                            }
                                                                                                           
                                                                                                            /***********set circle**************/
                                                                                                            if($validation =='valid'){
                                                                                                                        $mobilenum1=$mobilenum;
                                                                                                                       
                                                                                                                        $getcirop=mysqli_query($concar,"select `msc`.`circle`,`msc`.`operator` from `msc` where `msc`.`msc`=left('".$mobilenum1."',5)");
                                                                                                                       
                                                                                                                        $rocirop=mysqli_fetch_array($getcirop);
                                                                                                                        $circle=$rocirop['circle'];
                                                                                                                        $operator=$rocirop['operator'];
                                                                                                                        }
                                                                                                            /*************************************/
                                                                                                           
                                                                                                           
                                                                                                           
                                                                                                           
                                                                                                           
/*echo $up="update `car_rawdata` set `mobile1`='$mobilenum', `validation`='$validation',`circle`='$circle',`operator`='$operator' where `id`='$id'";

echo '<br/>';       */                                                                         
$updatedt=mysqli_query($concar,"update `car_rawdata` set `mobile1`='$mobilenum', `validation`='$validation',`circle`='$circle',`operator`='$operator' where `id`='$id'");
                                                                                                           
}// end while
               
//echo 'filename---'.$filename;                                                                                 
$trct=mysqli_query($concar,"delete from `setcolumn` where `filename`='$filename'");


}//end while
Krish307
 
Posts: 2
Joined: 28. May 2015 11:12
Operating System: Windows Server 2008

Re: Fatal error: Out of memory

Postby Nobbie » 28. May 2015 15:13

Never ever do a "Select *" with many hits, it produces to big amount of data, which is stored temporarily.

Instead do a "Select id ...", where id is the Primary Key, and after you fetch all ids, one after the other into $id and do a "Select ..... from table where id = $id" (specify the columns you need, in this special case you also may use "*"), this selects only one line per call.

This safes you huge amount of memory and also runs pretty much faster (some people are wrong when they believe, that many Selects on the primary key slows down the whole process, but this is definately wrong). Try to change your code and it *should* run by far better.

P.S.: I did it for you, you only have to replace "id" by your primary key (if it is not "id")

Replace:

Code: Select all
$query=mysqli_query($concar,"select * from `car_rawdata` where `filename`='$filename' and `validation`=''");
while($row=mysqli_fetch_array($query)){


by:

Code: Select all
$query=mysqli_query($concar,"select `id` from `car_rawdata` where `filename`='$filename' and `validation`=''");
while($row_id=mysqli_fetch_array($query)){
$id = $row_id['id'];
$row_query=mysqli_query($concar, "select * from `car_rawdata` where `id` = $id`");
$row=mysqli_fetch_array($row_query);
Last edited by Nobbie on 28. May 2015 15:33, edited 1 time in total.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: Fatal error: Out of memory

Postby mark.mcdonald » 28. May 2015 15:31

You are grabbing over a Gig of information (1185153024 = 1.185G). I would recommend modifying your queries as Nobbie has suggested (I second this motion) and this will become faster and more reliable by being specific to the data you want. Select * is every database administrator's worst nightmare.
mark.mcdonald
 
Posts: 160
Joined: 13. March 2015 15:48
Location: Edmonton
Operating System: Windows Server 2012 R2


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 112 guests