1. Go to this page and download the library: Download phpner/laravel-profiler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Illuminate\Console\Command;
use Phpner\MemoryProfiler\Console\Concerns\ProfilesMemory;
class ImportUsers extends Command
{
use ProfilesMemory;
protected $signature = 'users:import';
public function handle(): int
{
return $this->withMemoryProfiling(function () {
// your command logic
$this->info('Importing...');
// ...
return 0; // exit code
});
}
}
use Phpner\MemoryProfiler\MemoryProfiler; // service
use Phpner\MemoryProfiler\Facades\MemoryProfiler as MP; // facade
// 1) Service
public function show(MemoryProfiler $profiler)
{
$ctx = $profiler->start('code');
// ... your code ...
$profiler->stop($ctx, [
'label' => 'users.show',
'meta' => ['id' => 42],
]);
}
// 2) Facade
$ctx = MP::start('code');
// expensive work
MP::stop($ctx, ['label' => 'expensive.segment']);