PHP 8 with Xdebug 3 on Apple M1

Hits: 242

We can install Xdebug via pecl on MacOS with Homebrew. Paste that in terminal.

pecl install xdebug

And see if the php interpreter with Xdebug working:

d8devs@MBP-von-d8devs project % php -v
PHP 8.0.8 (cli) (built: Jul 12 2021 02:58:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies

to correctly configuration Xdebug, locate (or create) section in php.ini file. Finding your currently php.ini location, type this in terminal: php --ini

Open the php.ini file.

vim /opt/homebrew/etc/php/8.0/php.ini

add it as follows at the last lines of file

; List of h....
.....
...

xdebug.mode = debug
xdebug.client = 127.0.0.1
xdebug.idekey = PHPSTORM
xdebug.start_with_request = yes

Enjoy! 😊

PHP 8 Installation on Mac M1 via homebrew

Hits: 18359

Install first homebrew, if it is not already installed. Paste that in macOS Terminal.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

And follow the ==> Next steps: after Installation add homebrew to your PATH

Actually Default Image for php from Brew Package Repository is a PHP 8. Here we can see that:

Thats means, we can simple install the php 8 in a macOS Terminal with this command brew install php, but we want to explicit install version 8, other versions can be declared as standard in the future. Paste that in terminal

brew install php@8.0

after that, you should be linked the installed php as system default php interpreter, for that run this command in terminal

brew link php

after restarting terminal, you must be see this output

d8devs@MBP-von-d8dev ~ % php -v
PHP 8.0.8 (cli) (built: Jul 12 2021 02:58:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies

Enjoy 😉

PHP – Big File Operation with Generator

Hits: 196

<?php
class CsvReader
{
    protected $file;
 
    public function __construct($filePath) {
        $this->file = fopen($filePath, 'r');
    }
 
    public function rows()
    {
        while (!feof($this->file)) {
            $row = fgetcsv($this->file, 4096);

            yield $row;
        }
        
    }
}
 
$csv = new CsvReader('/path/to/big/csv/file.csv');

foreach ($csv->rows() as $row) {
    // the CSV row.
}

PHPStorm – Symfony log highlighting

Hits: 195

To do, go into Settings -> Editor -> Log Highlighting (Ideolog)

Add new Log Format with the following config:

Name: Symfony
Message Pattern: ^\[(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\]\s+(\w+).(\w+):\s+(.*)$
Message start pattern: ^\[
Time format: yyyy-MM-dd HH:mm:ss
Time capture group: 1
Severity capture group: 3
Category capture group: 2

special thanks to : https://locastic.com/blog/a-quick-way-to-browse-symfony-logs-with-phpstorm/

PHPStan Config for Standalone Chameleon Project

Hits: 96

Install

composer require --dev phpstan/phpstan

Standard phpstan.neon file for standalone chameleon project.

parameters:
    scanDirectories:
        - app/cache/autoclasses
    excludePaths:
        - src/*/Migration*
    level: 6
    paths:
        - src

Run:

 vendor/bin/phpstan analyse -c phpstan.neon