如何解决如何在 Laravel 中添加自定义的 ini_set
我想将数据从视图导出到实时服务器上的 CSV
文件中,但是每当我运行它时,我都会收到此错误:
超过最大执行时间 30 秒
这里是导出类:
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的具体函数的开头。
/**
* @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'));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。