lundi 31 octobre 2022

Laravel taking 100% MySQL DB CPU and no jobs visible in php artisan queue:listen, Laravel 5.7

The MySQL DB CPU is running at 95%+ basically at all times, even when there's seemingly no activity in the app. It doesn't happen right away. Only once the app has been running for a while, but then it keeps at 95% CPU even once there's seemingly no activity.

The number of active sessions / connections gradually climbs from dozens to even hundreds. Looking at the MySQL processes on RDS reveals a dozen processes trying to use 8% of the DB CPU each for some reason.

I've checked for Laravel jobs via php artisan queue:listen but nothing appears.

Checked the database and query logs, and there are many DB logs which suggest a job or something occurring in a loop, but no indication as to what the source of those jobs are as the queries being ran are generic queries and could be called from many different places in the application.

We do not believe this is due to user activity, but if it is, it's some kind of user action whicih results in some kind of a server loop.

Checked application and error logs and nothing in particular stands out.



via Chebli Mohamed

when i upload laravel website form local to live sever this error that i face can any one help me

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from sessions where id = E70KsnO9rKtK9ATW71zmd9AfGW1ek7nAhnD2wQjS limit 1) error that i face

any one help me to solve this



via Chebli Mohamed

samedi 29 octobre 2022

Laravel clearing config causing wierd X to show up

I'm currently using laravel 5.8 in a project and stumbled on a weird problem, after lanching the commande optimize:clear a Wierd Caracheter will show up when executing any other commande and also causing ajax requests to fail here is an example of the problem enter image description here

this happening in all the team machines, not just mine. the second problem reloading a page, every time We load a page we see this screen before it redirected to the actual view
enter image description here

the only found solution is to run the commande Artisan config:cache



via Chebli Mohamed

vendredi 28 octobre 2022

how to improve my performance for this complex query | Laravel , Datatabels

Hi everyone i have a very complex query to get Finance data, its like 4 Join and when the data is more than 1000 it getting slow when it loads in datatables how i can make it faster

this is the controller code for ajax :

  $financial_entries = FinanceEntryMod::select([
        DB::raw("ROUND(( 
            select SUM(finance_transaction.equivalent) from finance_transaction  where 
            finance_transaction.entry_id = financial_entries.id and
            finance_transaction.type = 'credit' 
        ), 2) as eqivalent_sum"),
        'financial_entries.id',
        'financial_entries.created_by',
        'financial_entries.branch_id',
        'financial_entries.order_id',
        'financial_entries.number',
        DB::raw('IFNULL(branches.name, IFNULL(v2_branches.name, "main_branch")) AS branch_name'),
        'financial_entries.v2_order_id as v2_order_id',
        'financial_entries.v2_document_id as v2_document_id',
        'financial_entries.date',
        'financial_entries.is_generated',
        'financial_entries.note',
        'financial_entries.created_at',
        'financial_entries.updated_at',
        DB::raw('
            DATE_FORMAT(financial_entries.date, "%Y-%m-%d") AS new_date,
            DATE_FORMAT(financial_entries.created_at, "%Y-%m-%d") AS new_created_at
        ')
    ])
    ->leftJoin('branches', function ($join) {
        $join->on("branches.id", "=", "financial_entries.branch_id");
    })
    ->leftJoin('finance_transaction', function ($join) {
        $join->on("financial_entries.id", "=", "finance_transaction.entry_id");
    })
    ->leftJoin('finance_accounts', function ($join) {
        $join->on("finance_accounts.id", "=", "finance_transaction.account_id");
    })
    ->leftJoin('v2_branches', function ($join) { 
        $join->on("v2_branches.id", "=", "finance_accounts.v2_branch_id"); 
    })
    ->where('financial_entries.is_deleted', '=', '0')
    ->groupBy('financial_entries.id');

and in the script : im using this

   "pageLength": 30,
        "serverSide"   : true,
        "processing"   : true,
        "columns": 

please help me to improve it thanks all



via Chebli Mohamed

jeudi 27 octobre 2022

MethodNotAllowedHttpException at RouteCollection->methodNotAllowed(array('POST'))

I'm trying to use POST to let user log in with correct email/password. I keep getting this error

MethodNotAllowedHttpException at RouteCollection->methodNotAllowed(array('POST'))

web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

Route::get('/', function () {
    return view('login');
});

Route::post("/login",[UserController::class,'login']);

UserController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
{
    //
    function login(request $req)
    {
        return $req->input();
    }
}

login.blade.php

@extends('master')
@section('content')
<div class="container custom-login">
    <div class="row">
        <div class="col-sm-4 col-sm-offset-4">
            <form action="/login" method="POST">
            <div class="form-group">
                @csrf
                <labe for="exampleInputEmail">Email address</label>
                <input type="email" name="email" class="form-control" id="exampleInputEmail" placeholder="Email">
            </div>
            <div class="form-group">
                <labe for="exampleInputPassword">Password</label>
                <input type="password" name="password" class="form-control" id="exampleInputPassword" placeholder="Password">
            </div>
            <button type="submit" class="btn btn-default">Login</button>
            </form>
        </div>
    </div>
</div>

@endsection

I tried opening the login page but POST is having issues. I expected the login page to use POST to check credentials in my database.



via Chebli Mohamed

mercredi 26 octobre 2022

How to make clean code laravel in my case

Hi i need to make this code clean to reduce performance from serve how can do that ? the code have request search, filter and export must change all code to have small code

Hi i need to make this code clean to reduce performance from serve how can do that ? the code have request search, filter and export must change all code to have small code

need to change this code to clean code with best performance in server

//request search
if ($request->filled('search')) {

            // $users = User::search($request->search)->paginate(10);

            $users = User::query()
                ->withCount('orders')
                ->where('id', 'Like', '%' . request('search') . '%')
                ->orwhere('first_name', 'Like', '%' . request('search') . '%')
                ->orwhere('last_name', 'Like', '%' . request('search') . '%')
                ->orwhere('mobile', 'Like', '%' . request('search') . '%')
                ->orwhere('email', 'Like', '%' . request('search') . '%')
                ->paginate(10);
//if have request search and need to check for export files and sort
            if ($request->filled('filter') or $request->filled('export')) {

                if ($request->filter == 0 and $request->export == 1) {
                    $users;
                    $pdf = Pdf::loadView('myPDF', compact('users'));
                    return $pdf->download('itsolutionstuff.pdf');
                } elseif ($request->filter == 0 and $request->export == 2) {
                    $users;
                    return Excel::download(new UsersExport($users), 'users-collection.xlsx');
                } elseif ($request->filter == 0 and $request->export == 3) {
                    $users;
                    return (new UsersExport($users))->download('Alphabetical.csv', \Maatwebsite\Excel\Excel::CSV);
                } elseif ($request->filter == 0) {
                    $users;
                }

                if ($request->filter == 1 and $request->export == 1) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('first_name')->paginate(10);
                    $pdf = Pdf::loadView('myPDF', compact('users'));
                    return $pdf->download('itsolutionstuff.pdf');
                } elseif ($request->filter == 1 and $request->export == 2) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('first_name')->paginate(10);
                    return Excel::download(new UsersExport($users), 'users-collection.xlsx');
                } elseif ($request->filter == 1 and $request->export == 3) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('first_name')->paginate(10);
                    return (new UsersExport($users))->download('Alphabetical.csv', \Maatwebsite\Excel\Excel::CSV);
                } elseif ($request->filter == 1) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('first_name')->paginate(10);
                }

                if ($request->filter == 2 and $request->export == 1) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('orders_count', 'desc')->paginate(10);
                    $pdf = Pdf::loadView('myPDF', compact('users'));
                    return $pdf->download('itsolutionstuff.pdf');
                } elseif ($request->filter == 2 and $request->export == 2) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('orders_count', 'desc')->paginate(10);
                    return Excel::download(new UsersExport($users), 'users-collection.xlsx');
                } elseif ($request->filter == 2 and $request->export == 3) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('orders_count', 'desc')->paginate(10);
                    return (new UsersExport($users))->download('Alphabetical.csv', \Maatwebsite\Excel\Excel::CSV);
                } elseif ($request->filter == 2) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('orders_count', 'desc')->paginate(10);
                }

                if ($request->filter == 3 and $request->export == 1) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('orders_count', 'desc')->orderBy('first_name')->paginate(10);
                    $pdf = Pdf::loadView('myPDF', compact('users'));
                    return $pdf->download('itsolutionstuff.pdf');
                } elseif ($request->filter == 3 and $request->export == 2) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('orders_count', 'desc')->orderBy('first_name')->paginate(10);
                    return Excel::download(new UsersExport($users), 'users-collection.xlsx');
                } elseif ($request->filter == 3 and $request->export == 3) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('orders_count', 'desc')->orderBy('first_name')->paginate(10);
                    return (new UsersExport($users))->download('Alphabetical.csv', \Maatwebsite\Excel\Excel::CSV);
                } elseif ($request->filter == 3) {
                    $users = User::query()->withCount('orders')->where('id', 'Like', '%' . request('search') . '%')->orwhere('first_name', 'Like', '%' . request('search') . '%')->orwhere('last_name', 'Like', '%' . request('search') . '%')->orwhere('mobile', 'Like', '%' . request('search') . '%')->orwhere('email', 'Like', '%' . request('search') . '%')->orderBy('orders_count', 'desc')->orderBy('first_name')->paginate(10);
                }

            }
//if not have request search and need to make filter sort
        } elseif ($request->filled('filter')) {

            if ($request->filter == 1 and $request->export == 1) {
                $users = User::withCount('orders')->orderBy('first_name')->paginate(10);
                $pdf = Pdf::loadView('myPDF', compact('users'));
                return $pdf->download('itsolutionstuff.pdf');
            } elseif ($request->filter == 1 and $request->export == 2) {
                $users = User::withCount('orders')->orderBy('first_name')->paginate(10);
                return Excel::download(new UsersExport($users), 'users-collection.xlsx');
            } elseif ($request->filter == 1 and $request->export == 3) {
                $users = User::withCount('orders')->orderBy('first_name')->paginate(10);
                return (new UsersExport($users))->download('Alphabetical.csv', \Maatwebsite\Excel\Excel::CSV);
            } elseif ($request->filter == 1) {
                $users = User::withCount('orders')->orderBy('first_name')->paginate(10);


            } elseif ($request->filter == 2 and $request->export == 1) {
                $users = User::withCount('orders')->orderBy('orders_count', 'desc')->paginate(10);
                $pdf = Pdf::loadView('myPDF', compact('users'));
                return $pdf->download('Most_orders.pdf');
            } elseif ($request->filter == 2 and $request->export == 2) {
                $users = User::withCount('orders')->orderBy('orders_count', 'desc')->paginate(10);
                return Excel::download(new UsersExport($users), 'users-collection.xlsx');
            } elseif ($request->filter == 2 and $request->export == 3) {
                $users = User::withCount('orders')->orderBy('orders_count', 'desc')->paginate(10);
                return (new UsersExport($users))->download('invoices.csv', \Maatwebsite\Excel\Excel::CSV);
            } elseif ($request->filter == 2) {
                $users = User::withCount('orders')->orderBy('orders_count', 'desc')->paginate(10);


            } elseif ($request->filter == 3 and $request->export == 1) {
                $users = User::withCount('orders')->orderBy('id', 'DESC')->paginate(10);
                $pdf = Pdf::loadView('myPDF', compact('users'));
                return $pdf->download('Date_of_registration.pdf');
            } elseif ($request->filter == 3 and $request->export == 2) {
                $users = User::withCount('orders')->orderBy('id', 'DESC')->paginate(10);
                return Excel::download(new UsersExport($users), 'users-collection.xlsx');
            } elseif ($request->filter == 3 and $request->export == 3) {
                $users = User::withCount('orders')->orderBy('id', 'DESC')->paginate(10);
                return (new UsersExport($users))->download('invoices.csv', \Maatwebsite\Excel\Excel::CSV);
            } elseif ($request->filter == 3) {
                $users = User::withCount('orders')->orderBy('id', 'DESC')->paginate(10);


            } elseif ($request->filter == 0 and $request->export == 1) {
                $users = User::withCount('orders')->paginate(10);
                $pdf = Pdf::loadView('myPDF', compact('users'));
                return $pdf->download('Date_of_registration.pdf');
            } elseif ($request->filter == 0 and $request->export == 2) {
                $users = User::withCount('orders')->paginate(10);
                return Excel::download(new UsersExport($users), 'users-collection.xlsx');
            } elseif ($request->filter == 0 and $request->export == 3) {
                $users = User::withCount('orders')->paginate(10);
                return (new UsersExport($users))->download('invoices.csv', \Maatwebsite\Excel\Excel::CSV);
            } elseif ($request->filter == 0) {
                $users = User::withCount('orders')->orderBy('id', 'DESC')->paginate(10);
            }

        } else {
//if not have any request search
            $users = User::withCount('orders')->paginate(10);
        }
        return view('admin.users.index', compact('users'));


via Chebli Mohamed

I want to pull mysql export text from laravel

I want to pull mysql export text from laravel

INSERT INTO 'example' ('id', 'name') VALUES (1, 'example'), 
(2, 'example2'),
(3, 'example3'),
(4, 'example4');

Like this

Thank you.

I searched for sql query but couldn't find it



via Chebli Mohamed