我有一个程序需要3个数组(它们的长度相同,可以包含500个左右的数据)并将它们写入文本文件。PHP有保存“大”文件的问题
但是,我遇到了编写大文件的问题。数组是画布绘图应用程序的坐标和时间戳,所以我可以控制长度。我发现,一旦文件开始变得大于2MB,它不会保存文件。我设法保存的最大文件为2.18mb。从相关问题PHP: Having trouble uploading large files我已经确定,原因很可能是由于托管在免费托管服务器上。我已经看了phpinfo()函数,这里是4个有关数字:
memory_limit 16M
max_execution_time 30
upload_max_filesize 5M
post_max_size 5M
下面是相关编写代码:
// retrieve data from the JS
$x_s = $_GET['x_coords'];
$y_s = $_GET['y_coords'];
$new_line = $_GET['new_lines'];
$times = $_GET['time_stamps'];
print_r($_GET);
$randInt = rand(1,1000);
// first want to open a file
$file_name = "test_logs/data_test_" . $randInt . ".txt";
$file_handler = fopen($file_name, 'w') or die("Couldn't connect");
// For loop to write the data
for ($i = 0; $i < count($x_s); $i++){
// If new line want to write new line!
if (!$new_line[$i]){
if ($i!=0){
// If not the first line
fwrite($file_handler, "LINE_END\n"); }
fwrite($file_handler, "LINE_START\n");
}
// Write the x coord, y coord, timestamp
fwrite($file_handler, $x_s[$i] . ", ". $y_s[$i] .", ". $times[$i]. "\n");
// If last line then write last LINE_END
if ($i == (count($x_s)-1)){
fwrite($file_handler, "LINE_END\n"); }
}
fclose($file_handler);
我已经在我的本地设置一个PHP服务器和访问到错误日志。这就是我所得到的。
[Fri Mar 23 20:03:02 2012] [error] [client ::1] request failed: URI too long (longer than 8190)
问题解决的问题:问题是,我使用GET发送大量的数据,这些数据被追加到URI的。一旦URI达到8190个字符就会出错。使用POST解决了这个问题。
您是否在服务器上安装了suhosin补丁程序? – piotrekkr 2012-03-23 12:54:09
正如我所说这是在一个免费的网络服务器,所以不知道 – 2012-03-23 13:05:37
它是显示当你调用'phpinfo();' – chiborg 2012-03-23 13:13:09