我使用的是PHP7.4和Ci4.19
我正在阅读的文件小于14 MB。我得到以下两个错误;
Fatal error: Allowed memory size of 157286400 bytes exhausted (tried to allocate 20480 bytes) in /var/www/example.com/development.example.com/app_dir/vendor/codeigniter4/framework/system/Common.php on line 395
和这个;
Fatal error: Allowed memory size of 157286400 bytes exhausted (tried to allocate 20480 bytes) in /var/www/example.com/development.example.com/app_dir/vendor/codeigniter4/framework/system/Debug/Exceptions.php on line 154
在我的php.ini文件中,我有以下设置,是的,我在更改设置后重新启动了apache 2;
memory_limit = 150M
post_max_size = 150M
不知道我得到这个错误和如何修复它。
她是代号;
public function ski_index()
{
helper("filesystem");
// Read the JSON file
$json = file_get_contents(WRITEPATH.'/ski/raw_data/ski_areas.geojson');
// Decode the JSON file to an array
$array_data = json_decode($json,true);
// for the view
$this->data['array_data'] = $array_data;
// $new_array will collected filtered ski resorts by country
$new_array = array();
$j=1;
foreach ($array_data['features'] as $value){
// if isset and filter by country
if (isset($value['properties']['location']['iso3166_1Alpha2']) && $value['properties']['location']['iso3166_1Alpha2'] == 'JP'){
array_push($new_array, $value);
$j++;
}
}
// reconstruct by putting the array into FeatureCollection
$reassemble_data = array ('type'=>'FeatureCollection', 'features'=>$new_array);
// convert it back to json/geojson
$this->data['new_array'] = json_encode($reassemble_data);
//write out to new file
$file_content = $this->data['new_array'];
if (!write_file(WRITEPATH."/ski/filtered_data/japan_ski_resorts.geojson", $file_content)){
echo "Error - cannot write to path";
} else {
echo "Success - written to file";
}
return view('/Admin/Ski/ski_index', $this->data );
}
1条答案
按热度按时间nxowjjhe1#
默认情况下,PHP变量通过值传递。如果创建变量来存储值,则会有该数据的克隆,这需要更多内存。节省内存的一种方法是避免创建大量变量来存储相同的数据。例如:
请参阅下面的代码,了解如何使用更少的不需要的变量。