我的项目必须从Excel文件读取一些数据并插入到数据库中,它在我自己的服务器中完美运行,但我想在最终服务器中做同样的事情。我试过改变内存的最大值,时间执行等,但没有。
服务器有Windows Server 2012并使用IIS提供网页,实际上我不知道服务器是如何配置的,我什么都不能移动'因为用于另一个系统,业主不希望我改变一切。
PHP的错误日志返回它:
[07-Sep-2016 13:44:53 ] PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 32 bytes) in C:\inetpub\wwwroot\systrucking\liquidaciones\acciones\obtenerListaSucursales.php on line 16
[07-Sep-2016 13:45:11 ] PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 148 bytes) in C:\inetpub\wwwroot\systrucking\Php\PHPExcel_1.8.0\Classes\PHPExcel\Shared\String.php on line 96
[07-Sep-2016 13:45:18 ] PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 32 bytes) in C:\inetpub\wwwroot\systrucking\liquidaciones\acciones\obtenerListaSucursales.php on line 16
[07-Sep-2016 13:45:25 ] PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 148 bytes) in C:\inetpub\wwwroot\systrucking\Php\PHPExcel_1.8.0\Classes\PHPExcel\Shared\String.php on line 96
我的代码:
<?php
include("../../Php/smarker.php");
include("../../Php/PHPExcel_1.8.0/Classes/PHPExcel.php");
session_start();
$smarker = new Smarker();
$mysqli = new mysqli($smarker->getIP(),$smarker->getUsuario(), $smarker->getContrasena(), $smarker->getBD());
if(isset($_POST["envio"])){
if(isset($_FILES['archivo'])){
if ($_FILES['archivo']["error"] > 0){
echo "Error: " . $_FILES['archivo']['error'] . "<br>";
}
else{
move_uploaded_file($_FILES['archivo']['tmp_name'],"" . $_FILES['archivo']['name']);
set_time_limit ( 3000 );
}
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($_FILES['archivo']['name']);
$objWorksheet = $objPHPExcel->setActiveSheetIndex(1);
$i = 7;
do{
$solicitud = "INSERT INTO smkr_solicitud_inditex (id_solicitud, concepto, folio_inditex, fecha_recepcion, fecha_servicio, observaciones) VALUES (";
$conceptos = "INSERT INTO smkr_conceptos_inditex (id_solicitud, dev, conf, calz, mat) VALUES (";
$cps = "INSERT INTO smkr_cps (id_solicitud, cp_ida, cp_dev) VALUES (";
$query = "SELECT MAX(id_porcentaje) AS por, MAX(s.id_solicitud) AS sol from smkr_porcentajes_facturacion AS p, smkr_solicitud_inditex AS s";
$resultado = $mysqli->query($query);
$info_campo = $resultado->fetch_assoc();
$id_porcentaje = ($info_campo['por']!=null)?$info_campo['por']:"0";
$id_solicitud = ($info_campo['sol']!=null)?$info_campo['sol']:"0";
$solicitud .= (($id_solicitud*1)+1) . ",'" . $objWorksheet->getCellByColumnAndRow(0 , $i)->getValue() . "','" .
$objWorksheet->getCellByColumnAndRow(4 , $i)->getValue() . "','";
if(($objWorksheet->getCellByColumnAndRow(5 , $i)->getValue()!="")){
$timestamp = PHPExcel_Shared_Date::ExcelToPHP($objWorksheet->getCellByColumnAndRow(5 , $i)->getValue());
$fecha_php = date("Y-m-d",$timestamp);
}else{$fecha_php = "0000-00-00";}
if($objWorksheet->getCellByColumnAndRow(6 , $i)->getValue()!=""){
$timestamp = ($objWorksheet->getCellByColumnAndRow(6 , $i)->getValue()!="")? PHPExcel_Shared_Date::ExcelToPHP($objWorksheet->getCellByColumnAndRow(6 , $i)->getValue()):"";
$hora_php = date("H:i:s",$timestamp);
}else{$hora_php ="00:00:00";}
if(($objWorksheet->getCellByColumnAndRow(7 , $i)->getValue()!="")){
$timestamp = PHPExcel_Shared_Date::ExcelToPHP($objWorksheet->getCellByColumnAndRow(7 , $i)->getValue());
$fecha_php1 = date("Y-m-d",$timestamp);
}else{$fecha_php1 = "0000-00-00";}
if($objWorksheet->getCellByColumnAndRow(8 , $i)->getValue()!=""){
$timestamp = ($objWorksheet->getCellByColumnAndRow(8 , $i)->getValue()!="")? PHPExcel_Shared_Date::ExcelToPHP($objWorksheet->getCellByColumnAndRow(8 , $i)->getValue()):"";
$hora_php1 = date("H:i:s",$timestamp);
}else{$hora_php1 ="00:00:00";}
if($objWorksheet->getCellByColumnAndRow(22 , $i)->getValue() != ""){
$dev = 1;
}
else {$dev = 0;}
if($objWorksheet->getCellByColumnAndRow(23 , $i)->getValue() != ""){
$con = 1;
}
else {$con = 0;}
if($objWorksheet->getCellByColumnAndRow(24 , $i)->getValue() != ""){
$cal = 1;
}
else {$cal = 0;}
if($objWorksheet->getCellByColumnAndRow(25 , $i)->getValue() != ""){
$mat = 1;
}
else {$mat = 0;}
$solicitud .= $fecha_php. " " . $hora_php . "','" . $fecha_php1. " " . $hora_php1 . "','" . $objWorksheet->getCellByColumnAndRow(21 , $i)->getValue() . "')";
$mysqli->query($solicitud);
$cps .= (($id_solicitud*1)+1) . ",'" . $objWorksheet->getCellByColumnAndRow(1 , $i)->getValue() . "','" . $objWorksheet->getCellByColumnAndRow(2 , $i)->getValue() . "')";
$mysqli->query($cps);
$conceptos .= (($id_solicitud*1)+1) ."," . $dev . "," . $con . "," . $cal . "," . $mat . ");";
$mysqli->query($conceptos);
unset($p);
$p[] = array($objWorksheet->getCellByColumnAndRow(10 , $i)->getValue(), 1);
$p[] = array($objWorksheet->getCellByColumnAndRow(11 , $i)->getValue(), 2);
$p[] = array($objWorksheet->getCellByColumnAndRow(12 , $i)->getValue(), 3);
$p[] = array($objWorksheet->getCellByColumnAndRow(13 , $i)->getValue(), 4);
$p[] = array($objWorksheet->getCellByColumnAndRow(14 , $i)->getValue(), 5);
$p[] = array($objWorksheet->getCellByColumnAndRow(15 , $i)->getValue(), 6);
$p[] = array($objWorksheet->getCellByColumnAndRow(16 , $i)->getValue(), 7);
$p[] = array($objWorksheet->getCellByColumnAndRow(17 , $i)->getValue(), 8);
$p[] = array($objWorksheet->getCellByColumnAndRow(18 , $i)->getValue(), 9);
$p[] = array($objWorksheet->getCellByColumnAndRow(19 , $i)->getValue(), 10);
$p[] = array($objWorksheet->getCellByColumnAndRow(20 , $i)->getValue(), 11);
$suma = 0;
foreach($p as $r){
$porcentaje = "INSERT INTO smkr_porcentajes_facturacion ( id_solicitud, id_cliente, porciento) VALUES (";
$porcentaje .= (($id_solicitud*1)+1) ."," . $r[1] . ", " . $r[0] . ")";
if($r[0]!=""){
$suma += $r[0]*1;
$mysqli->query($porcentaje);
}
}
if ($suma*1==100){
$estado = 0;
}else{
$estado = 100;
}
$update = "UPDATE smkr_solicitud_inditex SET id_estado =" .$estado. " WHERE id_solicitud = ".(($id_solicitud*1)+1);
$mysqli->query($update);
if($estado == "100"){
$insert = "INSERT INTO smkr_estados VALUES (null,".(($id_solicitud*1)+1).", 0, NOW())";
$mysqli->query($insert);
}
$insert = "INSERT INTO smkr_estados VALUES (null,".(($id_solicitud*1)+1).", ".$estado.", NOW())";
$mysqli->query($insert);
$i++;
}while( $objWorksheet->getCellByColumnAndRow(1 , $i)->getValue() != "" || $objWorksheet->getCellByColumnAndRow(2 , $i)->getValue() != "");
unlink( $_FILES['archivo']['name']);
$_SESSION["resultado"] = "Se insertaron ".($i-7)." registros";
header("Location: http://".$smarker->getDireccion()."/systrucking/liquidaciones/");
}
else{
$_SESSION["resultado"] = "Error de archivo";
header("Location: http://".$smarker->getDireccion()."/systrucking/fletes/");
}
}else{
header("Location: http://".$smarker->getDireccion()."/systrucking/fletes/");
}
?>
我希望你能帮助我,坦克你!
答案 0 :(得分:0)
您可以在脚本中增加分配的内存,如下所示:
ini_set('memory_limit', '256M');
//适当更改内存值。