如何扩展 php 内存限制?
How to extend php memory limit?
我想要一个按钮,点击它会生成一个类似于前一个页面(按钮所在的页面)的页面,并自动将用户发送到打印选项页面。此页面包含来自 sybase 数据库的数据,我是通过 odbc 获取的。
问题是,在尝试生成打印页面时,由于 "out of memory problem".
,我无法获取该页面
错误:
Fatal error: Out of memory (allocated 392167424) (tried to allocate
387973888 bytes) in
C:\xampp\htdocs\CodeIgniter\Samsic\application\models\Pagamentos_model.php
on line 83
是的,我在 Whosebug 上看到了大多数关于 "out of memory(..)trying to allocate (..)" 的类似问题。
这个不同,因为 none 对类似问题给出的答案在这里有效!
我试过了:
ini_set('memory_limit', '-1');
ini_set('memory_limit', '128M');
None 有效。
我正在使用 MVC,这是我使用的代码:
型号:
<?php
ini_set('memory_limit', '-1');
class Pagamentos_model extends CI_Model {
public function imprimir($ano,$codigo){
require(APPPATH.'libraries/odbc_conn.php');
$query = odbc_exec($db, 'Select * from GP_Vw_Valores_Pagos where Ano='.$ano.' and Codigo='.$codigo.' order by CD');
$row=odbc_fetch_array($query);
$output= '<h1 style="text-align: center;"> Pagamentos'.$ano.' </h1> <table class="table" style="width: 100%; margin-bottom:40px; margin-top: 15px; ">
<thead>
<tr style="font-size: 1em;margin-bottom: 15px;text-align: center;">
<th scope="col">CD</th>
<th scope="col">Descrição</th>
<th scope="col">Tipo</th>
<th scope="col">Janeiro</th>
<th scope="col">Fevereiro</th>
<th scope="col">Março</th>
<th scope="col">Abril</th>
<th scope="col">Maio</th>
<th scope="col">Junho</th>
<th scope="col">Julho</th>
<th scope="col">Agosto</th>
<th scope="col">Setembro</th>
<th scope="col">Outubro</th>
<th scope="col">Novembro</th>
<th scope="col">Dezembro</th>
</tr>
</thead>';
while($row){
$output .= '<tr style="text-align: center;">
<td>' .$row["CD"].'</td>
<td>'.iconv("CP850", "UTF-8", $row['Descricao']).'</td>
<td>VI</td>
<td>' .number_format($row['Vl01'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl02'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl03'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl04'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl05'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl06'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl07'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl08'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl09'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl10'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl11'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl12'] , 2, '.', '').'</td>
</tr>
<tr style="text-align: center;">
<td></td>
<td></td>
<td>QT</td>
<td>' .number_format($row['Qt01'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt02'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt03'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt04'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt05'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt06'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt07'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt08'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt09'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt10'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt11'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt12'] , 2, '.', '').'</td>
</tr> ';
}
return $output;
}
}
?>
控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pagamentos extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('Pagamentos_model', '', TRUE);
$this->load->library('session');
}
public function imprimir(){
$ano = addslashes($this->session->anop);
$codigo = addslashes($this->session->codigo);
$resultado = $this->Pagamentos_model->imprimir($ano,$codigo);
$data['resultado'] = $resultado;
$this->load->view('imprimirTemplate',$data);
}
}
视图(模板):
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
body{
font-size: 0.9em;
}
.container{
width: 100%;
height: 100%;
}
@media print {
@page { margin: 20px; }
body { margin: 1.6cm; }
}
table, th, td {
border: 1px solid black;
</style>
</head>
<body onload="window.print()">
<?php $this->load->view('header'); ?>
<?= $resultado; ?>
</body>
</html>
此时,我不知道下一步该怎么做,如果有人能提供帮助,我将不胜感激!
如果query和fetch成功,那么$row
就不会是false
,while($row)
就会无限循环。你想删除这个:
$row=odbc_fetch_array($query);
然后将其添加到循环中:
while($row=odbc_fetch_array($query)) {
我想要一个按钮,点击它会生成一个类似于前一个页面(按钮所在的页面)的页面,并自动将用户发送到打印选项页面。此页面包含来自 sybase 数据库的数据,我是通过 odbc 获取的。
问题是,在尝试生成打印页面时,由于 "out of memory problem".
,我无法获取该页面错误:
Fatal error: Out of memory (allocated 392167424) (tried to allocate 387973888 bytes) in C:\xampp\htdocs\CodeIgniter\Samsic\application\models\Pagamentos_model.php on line 83
是的,我在 Whosebug 上看到了大多数关于 "out of memory(..)trying to allocate (..)" 的类似问题。
这个不同,因为 none 对类似问题给出的答案在这里有效!
我试过了:
ini_set('memory_limit', '-1');
ini_set('memory_limit', '128M');
None 有效。
我正在使用 MVC,这是我使用的代码:
型号:
<?php
ini_set('memory_limit', '-1');
class Pagamentos_model extends CI_Model {
public function imprimir($ano,$codigo){
require(APPPATH.'libraries/odbc_conn.php');
$query = odbc_exec($db, 'Select * from GP_Vw_Valores_Pagos where Ano='.$ano.' and Codigo='.$codigo.' order by CD');
$row=odbc_fetch_array($query);
$output= '<h1 style="text-align: center;"> Pagamentos'.$ano.' </h1> <table class="table" style="width: 100%; margin-bottom:40px; margin-top: 15px; ">
<thead>
<tr style="font-size: 1em;margin-bottom: 15px;text-align: center;">
<th scope="col">CD</th>
<th scope="col">Descrição</th>
<th scope="col">Tipo</th>
<th scope="col">Janeiro</th>
<th scope="col">Fevereiro</th>
<th scope="col">Março</th>
<th scope="col">Abril</th>
<th scope="col">Maio</th>
<th scope="col">Junho</th>
<th scope="col">Julho</th>
<th scope="col">Agosto</th>
<th scope="col">Setembro</th>
<th scope="col">Outubro</th>
<th scope="col">Novembro</th>
<th scope="col">Dezembro</th>
</tr>
</thead>';
while($row){
$output .= '<tr style="text-align: center;">
<td>' .$row["CD"].'</td>
<td>'.iconv("CP850", "UTF-8", $row['Descricao']).'</td>
<td>VI</td>
<td>' .number_format($row['Vl01'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl02'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl03'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl04'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl05'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl06'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl07'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl08'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl09'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl10'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl11'] , 2, '.', '').'</td>
<td>' .number_format($row['Vl12'] , 2, '.', '').'</td>
</tr>
<tr style="text-align: center;">
<td></td>
<td></td>
<td>QT</td>
<td>' .number_format($row['Qt01'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt02'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt03'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt04'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt05'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt06'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt07'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt08'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt09'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt10'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt11'] , 2, '.', '').'</td>
<td>' .number_format($row['Qt12'] , 2, '.', '').'</td>
</tr> ';
}
return $output;
}
}
?>
控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pagamentos extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('Pagamentos_model', '', TRUE);
$this->load->library('session');
}
public function imprimir(){
$ano = addslashes($this->session->anop);
$codigo = addslashes($this->session->codigo);
$resultado = $this->Pagamentos_model->imprimir($ano,$codigo);
$data['resultado'] = $resultado;
$this->load->view('imprimirTemplate',$data);
}
}
视图(模板):
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
body{
font-size: 0.9em;
}
.container{
width: 100%;
height: 100%;
}
@media print {
@page { margin: 20px; }
body { margin: 1.6cm; }
}
table, th, td {
border: 1px solid black;
</style>
</head>
<body onload="window.print()">
<?php $this->load->view('header'); ?>
<?= $resultado; ?>
</body>
</html>
此时,我不知道下一步该怎么做,如果有人能提供帮助,我将不胜感激!
如果query和fetch成功,那么$row
就不会是false
,while($row)
就会无限循环。你想删除这个:
$row=odbc_fetch_array($query);
然后将其添加到循环中:
while($row=odbc_fetch_array($query)) {