我在PHP中处理文件时遇到了一个问题。当处理小文件时,可以看到输出。但是,当处理大文件时,它会显示这样的警告:
PHP致命错误:第644行上的C:中内存不足(已分配1068498944字节)(尝试分配133955584字节)
我们可以看到这样的代码:
<?php
$no_urut = 0;
//print_r($array_query_simantic_reletedness);
foreach ($val_simantic_reletedness as $doc_simantic_word) {
foreach ($array_query_simantic_reletedness as $text_simantic_current_key => $text_simantic_current_val) {
//get fix val
$status = 0;
$spe = 0;
$sr = 0;
if ($text_simantic_current_key == $doc_simantic_word) {
$status++;
$spe = 1;
}
$where_get_kamus = array('kata' => $text_simantic_current_key);
$get_kamus = $this->master->find_data($where_get_kamus, 'tb_kamus')->row_array();
// print_r($get_kamus);
//split kamus by ';'
$kamus_synonim = explode(';', $get_kamus['synonim']);
//split kata by '.'
foreach ($kamus_synonim as $key_word_split => $val_word_split) {
$kata_current_kamus = explode(';', $val_word_split);
//print_r($kata_current_kamus);
foreach ($kata_current_kamus as $key_current_word_doc => $val_current_word_doc) {
//split by doc
$word_split_doc = explode('.', $val_current_word_doc);
if (empty($word_split_doc[0])) {
continue;
}
if (isset($word_split_doc[1])) {
$word_split_slash = explode('|', $word_split_doc[1]);
}
// print_r($word_split_slash);
// ---- foreach for checking ---
foreach ($word_split_slash as $val_current_word_check) {
//print_r($val_current_word_check);
$val_current_word_check = str_replace(' ', '', $val_current_word_check);
$val_current_word_check = str_replace("\r", '', $val_current_word_check);
$val_current_word_check = str_replace("\t", '', $val_current_word_check);
$val_current_word_check = str_replace("\n", '', $val_current_word_check);
// print_r($val_current_word_check);
if ($doc_simantic_word == strtolower($val_current_word_check)) {
$status++;
// penentuan dmax
$where_get_spe_check = array('kata' => $doc_simantic_word);
$get_word_spe = $this->master->find_data($where_get_spe_check, 'tb_kamus')->row_array();
if ($get_kamus['dmax'] > $get_word_spe['dmax']) {
$dmax_spe = $get_kamus['dmax'];
} else {
$dmax_spe = $get_word_spe['dmax'];
}
//count spe
$spe = $get_kamus['dmax'] / $dmax_spe;
}
}
//---- end foreach for checking ----------------
//echo '<br>';
}
}
$no_urut++;
if ($status > 0) {
$val_view = 1;
} else {
$val_view = 0;
$spe = 0;
}
$sr = $spe * $val_view;
echo "
<tr>
<td>$no_urut</td>
<td>$text_simantic_current_key " . '=' . " $doc_simantic_word</td>
<td>$val_view</td>
<td>$spe</td>
<td>$sr</td>
</tr>
";
// echo '||';echo $no_urut;echo '|'; echo $text_simantic_current_key ; echo '=' ;echo $doc_simantic_word;echo '|'; echo $val_view;echo '|'; echo $spe;echo '|'; echo $sr;
}
}//end simantic word doc
?>
and i give the highlight for line 644 is
> echo "
<tr>
<td>$no_urut</td>
<td>$text_simantic_current_key " . '=' . " $doc_simantic_word</td>
<td>$val_view</td>
<td>$spe</td>
<td>$sr</td>
</tr>
> ";
But when i check my code in https://phpcodechecker.com/
i have the different notice like this :
Error: There is 1 more opening parenthesis '(' found
This count is unaware if parenthesis are inside of a string
and we can see the code :
$get_data_tema = $this->master->find_data(array('id_tema'=>$key_val_final),'tb_tema')->row_array();
echo 'nama tema " <b>'.$get_data_tema['nama'].'</b>"';
}
$array_post_input = array('text_soal'=> $data_post['text_soal'],
'a' =>$data_post['a'],
'b' =>$data_post['b'],
'c' =>$data_post['c'],
'd' =>$data_post['d'],
'e' =>$data_post['e'],
'answer' =>$data_post['answer'],
'guru_id'=> $this->session->userdata('id_current'),
'tema_id'=>0,
'mapel_id' =>$data_post['mapel_id'],
'gbrsoal' =>$data_post['gbrsoal'],'label_id'=>0,
);
$this->master->insert_data('tb_soal',$array_post_input);
我正在使用xampp版本v3.2.2和windows 8.1,RAM 8 GB与6,94可用,PHP版本5.6.15与codeigniter框架,我已经设置在内存限制内php.ini 512000000000000 M.那么,我应该做什么来解决我的问题?哪一行必须是我修复它?谢谢.
2条答案
按热度按时间vvppvyoh1#
第一个问题的解答:对于大量的数据,打印过程可能会消耗大量的资源。因此,将可打印的部分保存到一个数组中,并在所有 foreach 迭代完成后打印一次。注意:在我代码中查找
$results
。第二个问题的解答(如果我理解正确的话):删除该行后面的“}”字符
祝你好运
du7egjpx2#
尝试插入**ini_set('内存限制','1024 M');**在php文件中