PHP
#プログラミング
php設定情報
https://www.php.net/manual/ja/book.info.php
https://www.php.net/manual/ja/info.configuration.php#ini.max-execution-time
PHP型比較表
https://www.php.net/manual/ja/types.comparisons.php
PHP: 名前空間の使用法: エイリアス/インポート - Manual
max_execution_tim
phpが使用可能な最大メモリ
max_execution_tim
phpの最大実行可能時間
max_input_tim
リクエストデータ解析時の最大実行可能時間
無制限にするとmax_execution_timeの時間が適用される
テスト
Codeception
Xdebug
Xdebug: Documentation » Supported Versions and Compatibility
PHPとのバージョン対応表
https://xdebug.org/docs/remote
The IP of the server is 10.0.1.2 with HTTP on port 80
The IDE is on IP 10.0.1.42, so xdebug.remote_host is set to 10.0.1.42
The IDE listens on port 9000, so xdebug.remote_port is set to 9000
The HTTP request is started on the machine running the IDE
Xdebug connects to 10.0.1.42:9000
Debugging runs, HTTP Response provided
パッケージマネージャー
composer
https://getcomposer.org/doc/00-intro.md
https://getcomposer.org/download/
code:composer.sh
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '8a6138e2a05a8c28539c9f0fb361159823655d7ad2deecb371b04a83966c61223adc522b0189079e3e9e277cd72b8897') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
pecl
拡張リポジトリ
install pecl
code:php-pecl.sh
#pecl
sudo apt install php-dev
sudo apt-get install php-pear
sudo pecl channel-update pecl.php.net
apt-get install -y libzip-dev
# 他にもありそう
セッションサーバー
https://pecl.php.net/package/redis
code:pecl
pecl install redis
# php5? redis-2.2.8
redis拡張
code:setup
apt install redis-server
pecl install redis
code:php.ini
session
extension=redis.so
session.save_handler = redis
session.save_path = "tcp://localhost:6379"
ignore
composer
https://kohkimakimoto.github.io/getcomposer.org_doc_jp/doc/00-intro.html
php.iniの以下をコメントアウト
iconv
rector refactoring
https://kohkimakimoto.github.io/getcomposer.org_doc_jp/doc/00-intro.html
code:sh
composer require rector/rector friendsofphp/php-cs-fixer symplify/easy-coding-standard --dev`
vendor/bin/rector process project_dir --level php74`
ビルトインウェブサーバー
https://www.php.net/manual/ja/features.commandline.webserver.php
code:server
cd ~/public_html
php -S localhost:8000 -t foo/
apacheにiniを読み込ませている場合reloadが必要。
------
php -r
php iniの場所を調べる
code:sh
php -r "echo phpinfo();" | grep "php.ini"
mysql
code:sh
php -r "var_dump(mysql_connect('host', 'user', 'password'));"
--------------------------
省略記法
以下の省略記法は非推奨
code:php
<? phpコード ?> //<?= phpコード?>で =を入れるべきのよう。
上記コードを実行するには、php.iniで以下の設定が必要
code:ini
short_open_tag = On
phpタグ
https://www.php.net/manual/ja/language.basic-syntax.phptags.php
https://www.php.net/manual/ja/ini.core.php#ini.short-open-tag
ログ
https://www.php.net/manual/ja/errorfunc.configuration.php
PHP 5.3 以降のデフォルトは E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED です。 この設定では E_NOTICE や E_STRICT、そして E_DEPRECATED レベルのエラーは出力されません
配列をロギングする場合
error_log(print_r($arr, true), 3, $logfile);
注意
phpのcli用iniと apacheで読み込まれる php.iniは異なる。
以下cliで読み込まれる。
/etc/php/7.4/cli/php.ini
REST
code:php
<?php
preg_match('|' . dirname($_SERVER'SCRIPT_NAME') . '/(\w%/*)|', $_SERVER'REQUEST_URI', $matches);
$paths = explode('/', $matches1);
$id = isset($paths1) ? htmlspecialchars($paths1) : null;
switch (strtolower($_SERVER'REQUEST_METHOD') . ':' . $paths0) {
case 'get:user':
PHP設定
php_value と php_admin_value の違い
php_admin_valueは上書きできない強制的な設定
mail.add_x_header