About significant changes in PHP 7.3

The following changes in PHP 7.3

– Flexible Heredoc syntax and Nowdoc syntax
– End comma can be used in function call JSON_THROW_ON_ERROR
– Can use reference passing with list () is_countable function
– array_key_first(), array_key_last()
– Argon2 Password Hash Enhancement

Flexible description of heredoc/nowdoc statement
You can now indent the end markers and the text you insert.

if(TRUE){
	print<<<EOS
	foo
	EOS;
}
&#91;/php&#93;

The indent of the string is determined relative to the end marker's position(indent). This allows you to easily control the number of spaces inserted etc. Note that mixing blanks and tabs in a string is not permitted, as it is controlled by indenting, and an error will occur.

<b>mbstring case conversion is enhanced</b>
The mbstring extension was originally developed to handle multi-byte strings, but it is actually used by many PHP programmers, including single-byte users, as extensions for string processing. As of PHP 7.3, upper and lower-case conversion mainly used in single-byte range is enhanced.


echo mb_strtoupper("Straße");

Allow commas to be inserted at the end of function arguments
Previously, in PHP 7.2 and earlier versions, although it was possible to write a comma at the end of the last element of the array, it was not possible to insert a comma at the end of function arguments. For example, when creating a function definition automatically by a script, putting a comma at the end may make writing code easier. In such cases, new features are useful.

$a = [1,2];
$b = [3,4];
$c = array_merge($a,$b,[5,6],);

is_countable(), array_key_*() function added
As of PHP 7.3, the is_countable() function has been added to check for countable functions. It can be used for purposes such as checking the functions that can be specified in the count() function.

if(is_countable($foo)){
	//$fooはカウント可
}

$a = ['one'=>'First','two'=>'Second','three'=>'Thred'];
echo array_key_first($a); // one
echo array_key_last($a); // three

Support for Same-site Cookie
A PHP session supports the Same-site Cookie(suggested as RFC 6265) that is said to be effective for cross-site request forgery(CSRF) protection as a security related function imrovement. When the SameSite attribute is specified, corss-site requests are limited and supported by major we browsers such as Google Chrome.

perl undef

Undefined values can be set using the undef function. Alternatively, the value of the variable specified in the argument is undefined.

#!/usr/bin/perl --

use strict;
use warnings;

print "Content-type:text/html\n\n";
my $name = "Kimoto";
$name = undef;

if (defined $name){
	print "defined";
} else {
	print "Undef";
}

なるほどー

mysqlのアップグレード

[vagrant@localhost ~]$ sudo yum remove -y mysql-community-release-el7-5.noarch
読み込んだプラグイン:fastestmirror
削除処理の設定をしています
引数に一致しません: mysql-community-release-el7-5.noarch
Determining fastest mirrors
* base: ftp.yz.yamagata-u.ac.jp
* extras: ftp.yz.yamagata-u.ac.jp
* remi-safe: mirror.xeonbd.com
* updates: mirror.vodien.com
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
extras/primary_db | 29 kB 00:00
jenkins | 2.9 kB 00:00
jenkins/primary_db | 127 kB 00:01
mariadb | 2.9 kB 00:00
mysql-connectors-community | 2.5 kB 00:00
mysql-tools-community | 2.5 kB 00:00
mysql56-community | 2.5 kB 00:00
nginx | 2.9 kB 00:00
nodesource | 2.5 kB 00:00
remi-safe | 3.0 kB 00:00
remi-safe/primary_db | 1.2 MB 00:02
updates | 3.4 kB 00:00
updates/primary_db | 3.7 MB 00:08

なんかものすごく怖いな。。

[vagrant@localhost ~]$ sudo yum localinstall -y http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
読み込んだプラグイン:fastestmirror
ローカルパッケージ処理の設定をしています
mysql57-community-release-el7-7.noarch.rpm | 8.8 kB 00:00
/var/tmp/yum-root-w9oAJm/mysql57-community-release-el7-7.noarch.rpm を調べています: mysql57-community-release-el7-7.noarch
/var/tmp/yum-root-w9oAJm/mysql57-community-release-el7-7.noarch.rpm をインストール済みとして設定しています
Loading mirror speeds from cached hostfile
* base: ftp.yz.yamagata-u.ac.jp
* extras: ftp.yz.yamagata-u.ac.jp
* remi-safe: mirror.xeonbd.com
* updates: mirror.vodien.com
依存性の解決をしています
–> トランザクションの確認を実行しています。
—> Package mysql57-community-release.noarch 0:el7-7 will be インストール
–> 衝突を処理しています: mysql57-community-release-el7-7.noarch は mysql-community-release と衝突しています
No package matched to upgrade: mysql57-community-release
–> 依存性解決を終了しました。
エラー: mysql57-community-release conflicts with mysql-community-release-el6-5.noarch
問題を回避するために –skip-broken を用いることができません
これらを試行できます: rpm -Va –nofiles –nodigest

なんだ。。

[vagrant@localhost ~]$ sudo yum swap -y — remove mysql-community-release — install http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
読み込んだプラグイン:fastestmirror
コマンド「swap」が見つかりません。「/usr/bin/yum –help」を実行してください。

あああああああ、ちょっとあんまりやりたくないなー

yum localinstall

Installs the specified package. You can also install multiple packages separated by single-byte spaces.

It is possible to skip confirmation of installation by adding “-y” option.

[vagrant@localhost ~]$ sudo yum localinstall jdk-8u40-linux-x64.rpm
読み込んだプラグイン:fastestmirror
ローカルパッケージ処理の設定をしています
ファイルが開けません: jdk-8u40-linux-x64.rpm を飛ばします。
何もしません

MySQL 8.0 Features

Document Store: Both relational and NoSQL applications can be developed in one DB.
Transactional data directory: implemented as a series of SQL tables stored in a single InnoDB tablespace.
SQL Role: Allows you to grant / remove privileges to groups of users, significantly reducing the burden of privilege management.
Default character set is utf8mb4: richer mobile applications and character set internalization
CTE(Common Table Expressions): Add WITH clause
Window function: Reduce code complexity and improve development productivity
Invisible Index: Better management of application upgrades and database changes running 24/7
Descending Index: Improves performance by eliminating the need to sort descending results
Json support: Add many functions such as JSON_TABLE function that receives JSON data and returns it as a relational table
Up to 2x faster: New benchmarks record up to 1.8 milion queries per second
OpenSSL: MySQL default TLS/SSL library
Performance schema: query execution time up to 30 times faster
Information schema: Query execution time is up to 100 times faster
GIS: supports SRS(Spatial Reference Systems)
Replication and InnoDB Cluster: Improve Scale Out of Large applilcations.

現状のバージョンを見てみると…

[vagrant@localhost ~]$ rpm -qa | grep -i mysql
php-mysqlnd-7.1.21-1.el6.remi.x86_64
mysql-community-common-5.6.41-2.el6.x86_64
mysql-community-devel-5.6.41-2.el6.x86_64
mysql-community-libs-5.6.41-2.el6.x86_64
mysql-connector-python-2.1.7-1.el6.x86_64
mysql-community-libs-compat-5.6.41-2.el6.x86_64
mysql-community-release-el6-5.noarch
mysql-community-client-5.6.41-2.el6.x86_64
mysql-utilities-1.6.5-1.el6.noarch
perl-DBD-MySQL-4.013-3.el6.x86_64
mysql-community-server-5.6.41-2.el6.x86_64
[vagrant@localhost ~]$ mysql –version
mysql Ver 14.14 Distrib 5.6.41, for Linux (x86_64) using EditLine wrapper
[vagrant@localhost ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> Ctrl-C — exit!
5.7か~

mysqlのアップグレードには
・mysql_upgradeを用いたアップグレード(インプレースアップグレード)
・レプリケーションを用いたアップグレード

Laravel5.7→5.8へのアップグレード

まず例にならって、5.7をcomposerでインストールします。

続いて、あ、その前に、公式ドキュメントを確認しておきましょう。
https://readouble.com/laravel/5.8/ja/upgrade.html

重要度の高い変更
キャッシュ持続時間が秒指定に
キャッシュロックの安全性向上
環境変数のパース
Markdownファイルのディレクトリ変更
Nexmo/Slack通知チャンネル

重要度が中程度の変更
コンテナジェネレーターとタグ付けサービス
SQLiteバージョン制約
ヘルパから文字列と配列クラスへ
遅延サービスプロバイダ
PSR-16準拠
不規則変化する複数形のモデル名
IDが増加するカスタムピボットモデル
Pheanstalk4.0

うーん、キャッシュに関することが多いですな。slackは上場するしねー
さて、composer.json

"license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0"
    },

はい、それでは、composerをアップデートします。

[vagrant@localhost tea]$ cp ../composer.phar composer.phar
[vagrant@localhost tea]$ php composer.phar update
[vagrant@localhost tea]$ php artisan --version
Laravel Framework 5.8.11

きたーーーーーーーーーーーー とりあえずお疲れ!
一仕事終わったので、サウナ行ってきます^^

laravel5.6→5.7へアップグレード

とりあえずアップグレードガイドのマニュアルを見てみる。
https://laravel.com/docs/5.7/upgrade

毎度のことながら、5.6.* →5.7.* に変更
composer.json

“require”: {
“php”: “^7.1.3”,
“fideloper/proxy”: “^4.0”,
“laravel/framework”: “5.7.*”,
“laravel/tinker”: “^1.0”
},
[/php]

[vagrant@localhost barley]$ cp ../composer.phar composer.phar
[vagrant@localhost barley]$ ls
app composer.lock package.json resources tests
artisan composer.phar phpunit.xml routes vendor
bootstrap config public server.php webpack.mix.js
composer.json database readme.md storage
[vagrant@localhost barley]$ php composer.phar update

[vagrant@localhost barley]$ php artisan –version
Laravel Framework 5.7.28

[vagrant@localhost barley]$ php artisan serve –host 192.168.35.10 –port 8000
Laravel development server started:
[Sun Apr 14 16:15:25 2019] 192.168.35.1:65342 [200]: /favicon.ico

はあああああああああああああ?????
なんだこれ?

laravel5.5→5.6 設定ファイルの変更・新規作成・削除

設定ファイル
laravel/app/Http/Middleware/TrustProxies.php ※変更

// protected $headers = [
    //     Request::HEADER_FORWARDED => 'FORWARDED',
    //     Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
    //     Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
    //     Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
    //     Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
    // ];
    protected $headers = Request::HEADER_X_FORWARDED_ALL;

laravel/config/hashing.php ※新規

return [
'driver'=>'argon',
];

laravel/config/logging.php ※新規

return [

'default'=>env('LOG_CHANNEL', 'stack'),

'channels' => [
 'stack'=> [
 	'driver'=>'stack',
 	'channels'=>['daily'],
 ],

 'single'=>[
 	'driver'=>'single',
 	'path'=> storage_path('logs/laravel.log'),
 	'level'=>'debug',
 ],

 'daily'=>[
 	'driver'=>'daily',
 	'path'=>storage_path('logs/laravel.log'),
 	'level'=>'debug',
 	'days'=> 30,
 ],

 slack=>[
 	'driver'=>'slack',
 	'url'=>env('LOG_SLACK_WEBHOOK_URL'),
 	'username'=>'Laravel_log',
 	'emoji'=>'.boom:',
 	'level'=>'critical',
 ],

 'syslog'=>[
 	'driver'=>'syslog',
 	'level'=>'debug',
 ],

 'errorlog'=>[
 	'driver'=>'errorlog',
 	'level'=>'debug',
 ],
],

];

laravel/config/app.php ※コメントアウト

// 'log' => env('APP_LOG', 'single'),
    // 'log_level' => env('APP_LOG_LEVEL', 'debug'),

[vagrant@localhost blog]$ php artisan serve –host 192.168.35.10 –port 8000
PHP Notice: Use of undefined constant slack – assumed ‘slack’ in /home/vagrant/local/app/laravel/blog/config/logging.php on line 25
Laravel development server started:
[Sun Apr 14 15:33:10 2019] PHP Notice: Use of undefined constant slack – assumed ‘slack’ in /home/vagrant/local/app/laravel/blog/config/logging.php on line 25
[Sun Apr 14 15:33:12 2019] PHP Notice: Use of undefined constant slack – assumed ‘slack’ in /home/vagrant/local/app/laravel/blog/config/logging.php on line 25
[Sun Apr 14 15:33:13 2019] 192.168.35.1:61897 [200]: /favicon.ico

これはやらんとわからんなー

The following exception is caused by a lack of memory or swap, or not having swap configured

The following exception is caused by a lack of memory or swap, or not having swap configured
なにこれ?

[vagrant@localhost blog]$ free -m
total used free shared buffers cached
Mem: 490 140 349 0 2 31
-/+ buffers/cache: 106 383
Swap: 991 658 333

swapは割り当てあります。
そもそもスワップファイルとは??
->使っていないメモリの内容を一時的にしまっておくためのファイル

スワップファイルを作成します
[vagrant@localhost blog]$ sudo -s /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 2.82202 s, 380 MB/s
[vagrant@localhost blog]$ sudo -s /sbin/mkswap /var/swap.1
スワップ空間バージョン1を設定します、サイズ = 1048572 KiB
ラベルはありません, UUID=e033e359-3fb0-4007-872a-73fc1e07ea10
[vagrant@localhost blog]$ sudo -s /sbin/swapon /var/swap.1

[vagrant@localhost blog]$ php composer.phar update
[vagrant@localhost blog]$ php artisan –version
Laravel Framework 5.6.39

おおおおおおおおおおおおおおおおおおおおおおおお
毎回リアクションが一緒になってきた。。

laravel5.5を入れて5.6へcomposer update

[vagrant@localhost laravel]$ php composer.phar create-project laravel/laravel blog “5.5.*”

[vagrant@localhost blog]$ php artisan –version
Laravel Framework 5.5.45
[vagrant@localhost blog]$ php -v
PHP 7.1.21 (cli) (built: Aug 15 2018 18:11:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

composer.json

"require": {
        "php": ">=7.1.3",
        "fideloper/proxy": "~4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "~1.0",
        "olssonm/l5-very-basic-auth":"5.*"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~7.0",
        "symfony/thanks": "^1.0"
    },

[vagrant@localhost blog]$ php composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 22 updates, 3 removals
– Removing symfony/polyfill-php70 (v1.11.0)
The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details

PHP Warning: proc_open(): fork failed – Cannot allocate memory in phar:///home/vagrant/local/app/laravel/blog/composer.phar/vendor/symfony/console/Application.php on line 952

Warning: proc_open(): fork failed – Cannot allocate memory in phar:///home/vagrant/local/app/laravel/blog/composer.phar/vendor/symfony/console/Application.php on line 952

[ErrorException]
proc_open(): fork failed – Cannot allocate memory

update [–prefer-source] [–prefer-dist] [–dry-run] [–dev] [–no-dev] [–lock] [–no-custom-installers] [–no-autoloader] [–no-scripts] [–no-progress] [–no-suggest] [–with-dependencies] [–with-all-dependencies] [-v|vv|vvv|–verbose] [-o|–optimize-autoloader] [-a|–classmap-authoritative] [–apcu-autoloader] [–ignore-platform-reqs] [–prefer-stable] [–prefer-lowest] [-i|–interactive] [–root-reqs] [–] []…