PHP
Install deprecated php-fpm version in Mac
in same cases you will need to install deprecated PHP version and this is no possible with these commands
brew tap shivammathur/php
brew install shivammathur/php/[email protected]
adding alias to use it
#echo 'alias php7.1="/opt/homebrew/opt/[email protected]/bin/php"' >> ~/.zshrc
#source ~/.zshrc
Force Composer to use a specific PHP version
to Force the composer to use a specific PHP version you can add this script to the composer.josn
"config": { "optimize-autoloader": true, "prepend-autoloader": false, "platform": { "php": "8.0.13" } },
or you can use the command line to add it
cd /path/to/project/dir ls -l composer.json composer config platform.php {PHP_VERSION_HERE} composer config platform.php 8.x.x
Sort a multidimensional array in PHP?
the most challenge question in the past was soring a multidimensional arrays in PHP, now lets make it in an easy way
You have your array like this
$array = [];
$array[] = array('name' => 'name1', 'age' => 85);
$array[] = array('name' => 'name2', 'age' => 15);
$array[] = array('name' => 'name3', 'age' => 10);
$array[] = array('name' => 'name4', 'age' => 59);
the easy way is to use these command
Clone repository with the same server user
Clone repository with the same server user
- create new php file with this name it.php
<?php exec('git clone https://@github.com/{username}/{repository}.git');
after that go to the command line and execute this command
php it.php
Merge text files using PHP code
the easiest and best way is to use the below code
<?php $txt1 = file_get_contents('1.txt'); $txt1 .= "\n" . file_get_contents('2.txt'); $txt1 .= "\n" . file_get_contents('3.txt'); $fp = fopen('newText.txt', 'w'); if(!$fp) die('Could not create / open text file for writing.'); if(fwrite($fp, $txt1) === false) die('Could not write to text file.'); echo 'Text files have been merged.'; ?>
use file_get_contents with POST and GET
usually in PHP we are using cURL to execute GET/ POST/ DELETE/ methods but now I will mention here how to use it in file_get_contents
Magento 2 Allowed Memory exhausted error when compile code
you need to increase the memory_limit in php.ini
and as a quick solution you can use these commands directly in the command line
php -dmemory_limit=5G bin/magento setup:di:compile
and
php -dmemory_limit=5G bin/magento setup:static-content:deploy
another code for the composer update
php -dmemory_limit=5G composer.phar update
php -d memory_limit=-1 /usr/local/bin/composer update
PHP 7.2 and use it instead of PHP 7.3 in Mac OS Catalina
- Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- brew install [email protected]
- echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
- echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.bash_profile
- source ~/.bash_profile
-open /private/etc/apache2/httpd.conf
- add this line "LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so"
PhpStorm disable auto-save
How to disable auto-save:
- Go to File > Settings (Ctrl+Alt+S).
- Go to Appearance & Behavior > System Settings.
- unchecked: the both fields
- Save files on frame deactivation
- Save files automatically if application is idle for x sec.
- Go to Editor > General > Editor Tabs
- Put a checkmark on
- "Mark modified files with asterisk"
Click Apply > OK.
That's it.
Show all PHP errors
The quickest way to display all php errors and warnings is to add these lines to your PHP code file:
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);