我编写了一个脚本,可以将XML文件上传到mySQL数据库。我遇到的问题是,大约15秒后,我收到"Internet Explorer无法显示网页"屏幕。
因为该文件略高于5MB,我认为问题与PHP中的"超时"或"文件大小"问题有关。经过一些研究,我想我已经找到了一种改变这一点的方法,希望能够下载该文件,所以我在PHP脚本的顶部插入了这些行。
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
ini_set('memory_limit', '6M'); //6 MB
我现在已经重新加载了文件和服务器,但我仍然遇到同样的问题,我已经不知道为什么会发生这种情况了。
PHP代码
<?
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
ini_set('memory_limit', '6M'); //6 MB
$objDOM = new DOMDocument();
$objDOM->load("xmlfile.xml");
$Details = $objDOM->getElementsByTagName("Details");
foreach( $Details as $value )
{
$listentry = $value->getElementsByTagName("listentry");
$listentrys = $listentry->item(0)->nodeValue;
$sitetype = $value->getElementsByTagName("sitetype");
$sitetypes = $sitetype->item(0)->nodeValue;
$sitedescription = $value->getElementsByTagName("sitedescription");
$sitedescriptions = $sitedescription->item(0)->nodeValue;
$siteosgb36lat = $value->getElementsByTagName("siteosgb36lat");
$siteosgb36lats = $siteosgb36lat->item(0)->nodeValue;
$siteosgb36lon = $value->getElementsByTagName("siteosgb36lon");
$siteosgb36lons = $siteosgb36lon->item(0)->nodeValue;
//echo "$listentrys :: $sitetypes :: $sitedescriptions :: $siteosgb36lats :: $siteosgb36lons <br>";
require("phpfile.php");
//Opens a connection to a MySQL server
$connection = mysql_connect ("hostname", $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can''t use db : ' . mysql_error());
}
mysql_query("INSERT IGNORE INTO scheduledsites (listentry, sitetype, sitedescription, siteosgb36lat, siteosgb36lon) VALUES('$listentrys','$sitetypes','$sitedescriptions','$siteosgb36lats','$siteosgb36lons') ")
or die(mysql_error());
}
echo "Data Inserted!";
?>
你可以试试我前几天提供给另一个StackOverflow成员的这个建议:
将其添加到htaccess文件:
<IfModule mod_php5.c>
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value memory_limit 300M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value session.gc_maxlifetime 1200
</IfModule>
有关这些设置的详细信息,请访问http://www.pacecode.com/blog/2008/09/22/magic-with-htaccess-file-increase-execution-time-session-expiry-time-and-file-upload-size-limit/