如何在 Laravel 中添加自定义 ini_set

How to add custom ini_set in Laravel

我想将视图中的数据导出到实时服务器上的 CSV 文件,但每当我 运行 它时,我都会收到此错误:

超过 30 秒的最长执行时间

这里是导出 Class:

class StudentExportView implements FromView {
    /**
     * @return \Illuminate\Support\Collection
     */
    public function view(): View {
        $student = new Student();
        $students = $student->searchStudents()->paginate(10);
        $custom = new Student();
        $customs = $custom->all();
        return view('admin.students.custom', compact('students','customs'));
    }
}

并且在控制器

public function export_view() {
    return Excel::download(new StudentExportView, 'studentlist.csv');
}

其实是数据量很大,所以才会出现这个错误。但是他们说如果我添加 ini_set('max_execution_time', 300); 我可以摆脱这个错误。

所以问题是在哪里添加这个自定义ini_set?我的意思是在 Controller 或 Export Class?

对于 运行 在线服务器上的这段代码有什么解决方案吗?

非常感谢你们的任何想法或建议。

提前致谢。

写在Controller的具体函数的开头。

   /**
     * @return \Illuminate\Support\Collection
     */
    public function view(): View
    {
        ini_set('max_execution_time', 0); // 0 = Unlimited
        $student = new Student();
        $students = $student->searchStudents()->paginate(10);
        $custom = new Student();
        $customs = $custom->all();
        return view('admin.students.custom', compact('students','customs'));
    }