【发布时间】:2015-07-06 10:10:24
【问题描述】:
您好,我有一个错误提示“致命错误:允许的内存大小为 134217728 字节已用尽(尝试分配 40 字节)”。
基本上,在 php 文件中,我提取了用户选择使用我在 ORACLE 数据库的包中创建的函数进行搜索的信息。在php中我调用函数,传入参数并显示所有结果。
<?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;
}
?>
而ORACLE中的功能是
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;
我尝试将ini_set('memory_limit', '-1'); 放在php 文件中,但它似乎不起作用。我还读到我必须增加变量?哪些变量在哪里?我能做些什么来解决这个问题?我不确定发生了什么。请,任何建议将不胜感激!
PS。我在数据库上尝试了该功能,效果很好
【问题讨论】:
-
更新 php.ini 文件后,您需要重新启动 Web 服务器以使其生效。我不确定 Windows/Mac,但在 Linux 上,您将拥有两个 php.ini 文件,一个用于 cli,一个用于您的 Web 服务器。
-
@Chad:128 MB 内存绰绰有余。算法应该改进。猜猜如果该脚本同时由 100 个用户运行会发生什么?想买主机?主要问题是脚本使用了太多内存,因为它一次读取所有内容,而不是一次处理每个位。请参阅下面的答案,以及下面我的评论...
-
@Michael 当然。但我没有提供答案,只是发表评论。