Home > Mobile >  Laravel 8 error vendor/symfony/polyfill-mbstring/Mbstring.php
Laravel 8 error vendor/symfony/polyfill-mbstring/Mbstring.php

Time:11-09

i want to ask about the problem i'm having. I'm using 2 desktops i.e. ubuntu and mint, when I run my code on ubuntu it runs smoothly. but if i run on mint desktop i have an error that says "Symfony\Component\ErrorHandler\Error\FatalError Maximum execution time of 60 seconds exceeded"

and i get this log on my terminal

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

and this is code on controller

        $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()]);
    }

can anyone help me with this problem? i had a similar experience when i tried to truncrate a string in my blade view. does it have something to do with the configuration in my php.ini?

thankss i hope get solution for this problem...

CodePudding user response:

This error appends when the max_execution_time of your PHP is reached. From the look of your error, it is probably set to 60 seconds.

You can increase this limit directly into your php.ini file (see with the command php --ini where it is located on your machine) or try to optimize your code.

If you don't want to edit the max_execution_time permanently, you can also add the instruction:

set_time_limit($seconds);

at the beginning of your script. I would not recommend this solution.

CodePudding user response:

You can set it in the php.ini file in the max_execution_time variable, the default is 60 seconds, you can change it according to your needs

  • Related