PHP Sandbox
PHP.net
References
Laravel illuminate
$capsule = new Capsule(); $capsule->addConnection($this->dbConfig); $capsule->setAsGlobal();
$capsule->bootEloquent(); $capsule->getDatabaseManager()->extend('mongodb', function ($config, $name) { $config['name'] = $name;
return new \Jenssegers\Mongodb\Connection($config); });
|
参数查看
php -r "phpinfo();" | grep configure
php --ini php -r "phpinfo();" | grep "Configuration File"
php -m
php --ri gd
php --re decimal
php -a
|
查看、修改内存限制
php -r "echo ini_get('memory_limit');"
php -r "phpinfo();" | grep memory
|
ini_set('memory_limit', '1024M');
set_time_limit(0);
|
Too Many Open Files
PHP-FPM Too Many Open Files 24 Error (set open file descriptor limit)
vim php-fpm.conf
;rlimit_files = 1024 rlimit_files = 4096
|
重启 PHP-FPM。
Composer
aliyun repo
阿里云 Composer 全量镜像
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
|
"config": { "disable-tls": true, "gitlab-domains": [], "optimize-autoloader": true, "preferred-install": { "*": "dist" } "secure-http": false, "sort-packages": true, }, "repositories": [ { "type": "cvs", "url": "..." }, { "type": "composer", "url": "https://mirrors.tencent.com/composer/" }, { "type": "composer", "url": "https://mirrors.aliyun.com/composer/" }, { "type": "composer", "url": "https://asset-packagist.org" } ]
|
忽略 php 版本限制
这个是极不推荐的,这样会造成库安装的版本错误。不应该使用。
composer require hellogerard/jobby --ignore-platform-reqs
|
推荐做法:
which composer
{正确的 PHP 版本}/bin/php /usr/local/bin/composer require hellogerard/jobby
/usr/local/opt/php@7.1/bin/php -d memory_limit=-1 /usr/local/bin/composer update -vvv
|
emory-limit-errors for more info on how to handle out of memory errors
php -d memory_limit=-1 /usr/local/bin/composer update
|
更新 composer.lock
若项目之前已通过其他源安装,则需要更新 composer.lock 文件:
homebrew PHP
🍺 Homebrew tap for PHP 5.6 to 8.2. PHP 8.2 is a nightly build.
shivammathur/homebrew-php
brew tap shivammathur/php
brew install shivammathur/php/php@8.1 -vvv
brew link --overwrite --force shivammathur/php/php@8.1 php -v
|
旧版本 MacOS 可以安装报错时尝试删除 XCode。
brew untap shivammathur/php
|
Real Client IP
$clientIP = $_SERVER['HTTP_CLIENT_IP'] ?? $_SERVER["HTTP_CF_CONNECTING_IP"] ?? $_SERVER['HTTP_X_FORWARDED'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['HTTP_FORWARDED'] ?? $_SERVER['HTTP_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
|
动态实例化类
class Test1{ public function __construct(){ echo "Test1<br>"; } }
$class1 = "Test1"; new $class1();
$class2 = "Test2";
$class2 = new ReflectionClass($class2);
$instance = $class2->newInstance();
|
– EOF –