Laravel 尝试打开 .txt 文件时出现最长执行时间错误

Laravel maximum execution time error when trying to open .txt file

我有一个包含国家及其代码的 .txt 文件,我想从中获取内容并插入到数据库中。 但是当为什么尝试使用 php 函数 fopen() 打开文件时,它会抛出最大执行时间错误 这是代码: web.php:

Route::get('/countries', 'PageController@insertCountries');

页面控制器:

public function insertCountries()
{
   $file = fopen(asset('databases/countries.txt'), 'r');
    return 'ok';
}

文件大小为6KB。我正在使用 Laravel 5.4 编辑: 文件位于文件夹数据库中的 mu public 文件夹中

如果你想打开本地文件,使用 File facade 直接使用文件系统,你也不应该使用 asset() helper。所以,改为做这样的事情:

$file = File::get('/full/path/to/the/file/countries.txt');