【问题标题】:Laravel 8 error vendor/symfony/polyfill-mbstring/Mbstring.phpLaravel 8 错误供应商/symfony/polyfill-mbstring/Mbstring.php
【发布时间】:2021-12-22 00:32:46
【问题描述】:

我想问一下我遇到的问题。我正在使用 2 个桌面,即 ubuntu 和 mint,当我在 ubuntu 上运行我的代码时,它运行顺利。但是如果我在薄荷桌面上运行,我会遇到一个错误,上面写着“Symfony\Component\ErrorHandler\Error\FatalError 最长执行时间超过 60 秒”

我在我的终端上得到了这个日志

Starting Laravel development server: http://127.0.0.1:8000
[Tue Nov  9 16:18:53 2021] PHP 8.0.12 Development Server (http://127.0.0.1:8000) started
[Tue Nov  9 16:18:55 2021] 127.0.0.1:38908 Accepted
[Tue Nov  9 16:18:55 2021] 127.0.0.1:38910 Accepted
[Tue Nov  9 16:20:22 2021] PHP Fatal error:  Maximum execution time of 60 seconds exceeded in /home/aditya/Documents/Laravel/eyrin/vendor/symfony/polyfill-mbstring/Mbstring.php on line 632
[Tue Nov  9 16:20:23 2021] 127.0.0.1:38908 Closing
[Tue Nov  9 16:20:23 2021] 127.0.0.1:38910 Closed without sending a request; it was probably just an unused speculative preconnection
[Tue Nov  9 16:20:23 2021] 127.0.0.1:38910 Closing

这是控制器上的代码

        $store = Store::where('user_id',Helper::getSession('user_id'))->first();
        
        $match_report = [];
        $top_weekly_product = [];

        $compressed_date = [];
        $uncompressed_date = Report::where('store_id',$store->id)->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->select('created_at')->distinct()->get();
        foreach ($uncompressed_date as $item) {
            if(!in_array(Carbon::parse($item['created_at'])->format('d/m/Y'),$match_report)){
                $match_report[] = Carbon::parse($item['created_at'])->format('d/m/Y');
                $compressed_date[] = $item;
            }
        }

        $match_report = [];

        $compressed_weekly_product = [];
        $uncompressed_weekly_product = Report::where('store_id',$store->id)->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get()->map(function($report){
            return [
                'product_name'=>$report->product_name,
                'product_variant'=>$report->product_variant,
                'product_sku'=>$report->product_sku,
                'weekly_amount'=>sizeof(Report::where(['store_id'=>$report->store_id, 'product_sku'=>$report->product_sku])->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get())
            ];
        });

        foreach ($uncompressed_weekly_product as $item) {
            if(!in_array($item['product_sku'],$match_report)){
                $match_report[] = $item['product_sku'];
                $compressed_weekly_product[] = $item;
            }
        }

        foreach ($compressed_weekly_product as $key => $item) {
            $rows = [];
            foreach ($compressed_date as $obj) {
                $rows[] = sizeof(Report::where(['store_id'=>$store->id, 'product_sku'=>$item['product_sku']])->whereDate('created_at', Carbon::parse($obj['created_at']))->get());
            }
            $compressed_weekly_product[$key]['daily_amount'] = $rows;
        }

        foreach ($compressed_date as $key => $item) {
            $compressed_date[$key]['formated'] = Carbon::parse($item->created_at)->format('m/d/Y');
        }

        $match_report = [];

        usort($compressed_weekly_product, function($a, $b) { 
            return $a['weekly_amount'] > $b['weekly_amount'] ? -1 : 1;
        }); 

        foreach ($compressed_weekly_product as $item) {
            if(sizeof($top_weekly_product) < 3){
                $top_weekly_product[] = $item;
            }
        }

        //testing
        $growth_percentage = 1.8;

        return view('panel.outlet.dashboard.index', [
            'is_dashboard'=>true,
            'total_customer'=>sizeof(Customer::where('store_id',$store->id)->get()),
            'total_revenue'=>Order::where('store_id',$store->id)->whereIn('status',['2','3','-'])->sum('total_amount'),
            'total_order'=>sizeof(Order::where('store_id',$store->id)->get()),
            'total_sales'=>sizeof(Order::where('store_id',$store->id)->whereIn('status',['2','3','-'])->get()),
            'total_product'=>sizeof(Product::where('store_id',$store->id)->get()),
            'total_sales_income'=>Order::where('store_id',$store->id)->whereIn('status',['2','3','-'])->sum('total_amount'),
            'growth_percentage'=>round($growth_percentage,2),
            'lastest_order'=>Order::where(['store_id'=>$store->id,'type'=>'app'])->orderBy('id','DESC')->limit(10)->get(),
            'report_date'=>$compressed_date,
            'top_weekly_product'=>$top_weekly_product,
            'weekly_product'=>$compressed_weekly_product,
            'weekly_report'=>DailyReport::where('store_id',$store->id)->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get()]);
    }

谁能帮我解决这个问题?当我尝试在刀片视图中截断字符串时,我也有类似的经历。和我的php.ini中的配置有关系吗?

谢谢,希望能解决这个问题...

【问题讨论】:

    标签: php laravel symfony mbstring


    【解决方案1】:

    当到达您的 PHP 的 max_execution_time 时,会附加此错误。从您的错误来看,它可能设置为 60 秒。

    你可以直接在你的 php.ini 文件中增加这个限制(使用命令 php --ini 查看它在你机器上的位置)或者尝试优化你的代码。

    如果不想永久修改max_execution_time,也可以添加指令:

    set_time_limit($seconds);
    

    在脚本的开头。我不会推荐这个解决方案。

    【讨论】:

    • 我已经通过增加 max_execution_time 来做到这一点,但仍然无法正常工作:",如果我重新安装了我的 php,则解决了
    【解决方案2】:

    您可以在max_execution_time变量中的php.ini文件中设置,默认为60秒,您可以根据需要更改

    【讨论】:

    • 我已经改变了这个值,但还是不行,我认为这个问题在我的 php.ini 上。因为我已经重新安装了我的 php / 我的 xampp,现在这个问题已经解决了
    猜你喜欢
    • 2017-10-19
    • 2021-04-19
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 2020-04-16
    • 2017-09-24
    • 2013-11-24
    • 2021-04-28
    相关资源
    最近更新 更多