简体   繁体   中英

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted

Hi I have an error that says "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 40 bytes)".

Basically, in the php file I extract the information that the user chooses to do a search with the function I created in a package in an ORACLE data base. In php I call the function, pass in the parameters and display all the results.

<?php  
$db_connection = oci_connect('DBadmin', 'dbadmin', 'PETLOVERSDB');
if (!$db_connection) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}   

$type =  $_GET['type'];  
echo $type;

$result;
$resultArray;
$finalResult = ' ';

$sqlVariableFindMyPets = 'BEGIN :pet_variable := pet_search_package.pet_search_type(:p_type_data);END;';   
$result = oci_new_cursor($db_connection);     

$dataToReceive = oci_parse($db_connection, $sqlVariableFindMyPets);      

oci_bind_by_name($dataToReceive, ':pet_variable', $result, -1, OCI_B_CURSOR);  
oci_bind_by_name($dataToReceive, ':p_type_data', $type); 
oci_execute($dataToReceive); 
oci_execute($result, OCI_DEFAULT); 
oci_fetch_all($result, $resultArray, null, null, OCI_FETCHSTATEMENT_BY_ROW);


oci_close($db_connection);  

if($resultArray == null){
    echo "<h2>No results found<h2>";
} else { 
    foreach($resultArray as $iterator){
        $finalResult = $finalResult.'<div class="col-lg-4 col-sm-6"> 
                                        <div class="properties">
                                            <form action="pet-detail.php" method="POST">
                                                <h4>'.$iterator['PET_TYPE_NAME'].' </h4>
                                                <div class="image-holder"><img src="images/logo2.png" class="img-responsive" alt="properties"/></div>
                                                <h5>'.$iterator['PET_RACE_NAME'].' </h5> 
                                                <h5>'.$iterator['PET_COLOR'].' </h5>  
                                                <h5>'.$iterator['PET_ENERGY_LEVEL'].'</h5>
                                                <h5>'.$iterator['PET_COND_NAME'].'</h5> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_code" value="'.$iterator['PET_CODE'].'"/>  
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_name" value="'.$iterator['PET_NAME'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_type" value="'.$iterator['PET_TYPE_NAME'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_race" value="'.$iterator['PET_RACE_NAME'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_cond" value="'.$iterator['PET_COND_NAME'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_energy" value="'.$iterator['PET_ENERGY_LEVEL'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_learn" value="'.$iterator['PET_LEARN_SKILL'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_vet" value="'.$iterator['VET_NAME'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_p_name" value="'.$iterator['PERSON_NAME'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_location" value="'.$iterator['PETLOCATION'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_notes" value="'.$iterator['PETNOTES'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_space" value="'.$iterator['PET_SPACE'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_treatment" value="'.$iterator['PET_TREATMENT'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_color" value="'.$iterator['PET_COLOR'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_sickness" value="'.$iterator['PET_SICKNESS_NAME'].'"/> 
                                                <input class="form-control" type="text" style="display: none" readonly name="pet_med" value="'.$iterator['PET_MED_NAME'].'"/>   
                                                <input type="submit" class="btn btn-primary" value="View Details" />
                                            </form>
                                        </div>
                                       </div>'; 
    }
    echo $finalResult;
}

?>

And the function in ORACLE is

CREATE OR REPLACE PACKAGE BODY pet_search_package AS
       FUNCTION pet_search_type(TYPEPET in VARCHAR2)
       RETURN SYS_REFCURSOR
       IS 
          pet_search_result SYS_REFCURSOR; 
          type_id NUMBER;

       BEGIN  

       select TP.pet_type_code into type_id
       from dbadmin.petType TP
       where TP.pet_type_name = TYPEPET;

    OPEN pet_search_result FOR select pet_type_name, pet_race_name, pet_cond_name, pet_energy_level, pet_learn_skill, vet_name, person_name, petlocation, petnotes, petabandondescription, pet_space, pet_treatment, pet_color, pet_sickness_name, pet_med_name
    from pet, pettype, petrace, petCondition, petSize,petEnergy, petlearningskill, veterinary, person, petSpace, pettreatments, petcolor, petsickness, petmedicine
    WHERE pettype.pet_type_code = type_id;
        RETURN pet_search_result; 

      EXCEPTION 
        WHEN NO_DATA_FOUND THEN 
          RETURN null;
      END; 

END pet_search_package;

I have tried putting ini_set('memory_limit', '-1'); on the php file but it doesn't seem to work. I also read that I have to increase variables ? which variables and where ? What can I do to solve this problem? Im not sure what is going on. Please, any suggestions would be appreciated !

PS. I tried the function on the database and works just fine

My guess is that you have a large table and your program fails while preparing the output.

instead of doing :

        foreach($resultArray as $iterator){
            $finalResult = $finalResult.'<div class="col-lg-4 col-sm-6"> 
                                            <div class="properties">
                                                <form action="pet-detail.php" method="POST">
                                                    <h4>'.$iterator['PET_TYPE_NAME'].' </h4>
                                                    <div class="image-holder"><img src="images/logo2.png" class="img-responsive" alt="properties"/></div>
                                                    <h5>'.$iterator['PET_RACE_NAME'].' </h5> 
                                                    <h5>'.$iterator['PET_COLOR'].' </h5>  
                                                    <h5>'.$iterator['PET_ENERGY_LEVEL'].'</h5>
                                                    <h5>'.$iterator['PET_COND_NAME'].'</h5> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_code" value="'.$iterator['PET_CODE'].'"/>  
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_name" value="'.$iterator['PET_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_type" value="'.$iterator['PET_TYPE_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_race" value="'.$iterator['PET_RACE_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_cond" value="'.$iterator['PET_COND_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_energy" value="'.$iterator['PET_ENERGY_LEVEL'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_learn" value="'.$iterator['PET_LEARN_SKILL'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_vet" value="'.$iterator['VET_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_p_name" value="'.$iterator['PERSON_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_location" value="'.$iterator['PETLOCATION'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_notes" value="'.$iterator['PETNOTES'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_space" value="'.$iterator['PET_SPACE'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_treatment" value="'.$iterator['PET_TREATMENT'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_color" value="'.$iterator['PET_COLOR'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_sickness" value="'.$iterator['PET_SICKNESS_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_med" value="'.$iterator['PET_MED_NAME'].'"/>   
                                                    <input type="submit" class="btn btn-primary" value="View Details" />
                                                </form>
                                            </div>
                                           </div>'; 
        }
        echo $finalResult;

try this foreach loop:

        foreach($resultArray as $iterator){
            echo '<div class="col-lg-4 col-sm-6"> 
                                            <div class="properties">
                                                <form action="pet-detail.php" method="POST">
                                                    <h4>'.$iterator['PET_TYPE_NAME'].' </h4>
                                                    <div class="image-holder"><img src="images/logo2.png" class="img-responsive" alt="properties"/></div>
                                                    <h5>'.$iterator['PET_RACE_NAME'].' </h5> 
                                                    <h5>'.$iterator['PET_COLOR'].' </h5>  
                                                    <h5>'.$iterator['PET_ENERGY_LEVEL'].'</h5>
                                                    <h5>'.$iterator['PET_COND_NAME'].'</h5> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_code" value="'.$iterator['PET_CODE'].'"/>  
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_name" value="'.$iterator['PET_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_type" value="'.$iterator['PET_TYPE_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_race" value="'.$iterator['PET_RACE_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_cond" value="'.$iterator['PET_COND_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_energy" value="'.$iterator['PET_ENERGY_LEVEL'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_learn" value="'.$iterator['PET_LEARN_SKILL'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_vet" value="'.$iterator['VET_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_p_name" value="'.$iterator['PERSON_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_location" value="'.$iterator['PETLOCATION'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_notes" value="'.$iterator['PETNOTES'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_space" value="'.$iterator['PET_SPACE'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_treatment" value="'.$iterator['PET_TREATMENT'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_color" value="'.$iterator['PET_COLOR'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_sickness" value="'.$iterator['PET_SICKNESS_NAME'].'"/> 
                                                    <input class="form-control" type="text" style="display: none" readonly name="pet_med" value="'.$iterator['PET_MED_NAME'].'"/>   
                                                    <input type="submit" class="btn btn-primary" value="View Details" />
                                                </form>
                                            </div>
                                           </div>'; 
        }

So just display the results as you iterate through them. Your code will have a more efficient use of memory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM