SmartWiki ?? ???? Alibaba Cloud? ???? ??? Alibaba Cloud?? 128M? ?? Memcache ???? ????. Memcached ?? ??? ?? ??? ? Laravel?? ??? ??? ?? ????? ?? ??? ??? ????. addServer? ??? ?? Alibaba Cloud? Memcache? ??? ? ????.
????? ???? ???? ?? ???? ????? ?? ??? ???? ???? ? ? ????.
Alibaba Cloud?? ???? ????? ??? ????.
<?php $connect = new Memcached; //聲明一個新的memcached鏈接 $connect->setOption(Memcached::OPT_COMPRESSION, false); //關(guān)閉壓縮功能 $connect->setOption(Memcached::OPT_BINARY_PROTOCOL, true); //使用binary二進(jìn)制協(xié)議 $connect->addServer('00000000.ocs.aliyuncs.com', 11211); //添加OCS實(shí)例地址及端口號 //$connect->setSaslAuthData('aaaaaaaaaa, 'password'); //設(shè)置OCS帳號密碼進(jìn)行鑒權(quán),如已開啟免密碼功能,則無需此步驟 $connect->set("hello", "world"); echo 'hello: ',$connect->get("hello"); print_r( $connect->getVersion()); $connect->quit();
laravel? Memcached ????? ???? /vendor/laravel/framework/src/Illuminate/Cache/MemcachedConnector? Memcached ??? ?????. .php ??? ??? ????.
public function connect(array $servers) { $memcached = $this->getMemcached(); // For each server in the array, we'll just extract the configuration and add // the server to the Memcached connection. Once we have added all of these // servers we'll verify the connection is successful and return it back. foreach ($servers as $server) { $memcached->addServer( $server['host'], $server['port'], $server['weight'] ); } $memcachedStatus = $memcached->getVersion(); if (! is_array($memcachedStatus)) { throw new RuntimeException('No Memcached servers added.'); } if (in_array('255.255.255', $memcachedStatus) && count(array_unique($memcachedStatus)) === 1) { throw new RuntimeException('Could not establish Memcached connection.'); } return $memcached; }
laravel? Memcached??? ?? ??? ?? ??? ???? getVersion? ???? ?? ??? ??????. ???????. Alibaba Cloud? ?? ??? ??? ?? ???? ???? ????? ???? ??? ?????.
??? ??? ????? Memcached? ??? ???? ??? ????. laravel? ?? ??? Cache::extend? ???? ??? ? ????. ?? ??? ??? ????.
Cache::extend('MemcachedExtend', function ($app) { $memcached = $this->createMemcached($app); // 從配置文件中讀取緩存前綴 $prefix = $app['config']['cache.prefix']; // 創(chuàng)建 MemcachedStore 對象 $store = new MemcachedStore($memcached, $prefix); // 創(chuàng)建 Repository 對象,并返回 return new Repository($store); });
/** * 創(chuàng)建Memcached對象 * @param $app * @return mixed */ protected function createMemcached($app) { // 從配置文件中讀取 Memcached 服務(wù)器配置 $servers = $app['config']['cache.stores.MemcachedExtend.servers']; // 利用 Illuminate\Cache\MemcachedConnector 類來創(chuàng)建新的 Memcached 對象 $memcached = new \Memcached; foreach ($servers as $server) { $memcached->addServer( $server['host'], $server['port'], $server['weight'] ); } // 如果服務(wù)器上的 PHP Memcached 擴(kuò)展支持 SASL 認(rèn)證 if (ini_get('memcached.use_sasl') && isset($app['config']['cache.storess.MemcachedExtend.memcached_user']) && isset($app['config']['cache.storess.MemcachedExtend.memcached_pass'])) { // 從配置文件中讀取 sasl 認(rèn)證用戶名 $user = $app['config']['cache.storess.MemcachedExtend.memcached_user']; // 從配置文件中讀取 sasl 認(rèn)證密碼 $pass = $app['config']['cache.storess.MemcachedExtend.memcached_pass']; // 指定用于 sasl 認(rèn)證的賬號密碼 $memcached->setSaslAuthData($user, $pass); } //擴(kuò)展 if (isset($app['config']['cache.stores.MemcachedExtend.options'])) { foreach ($app['config']['cache.stores.MemcachedExtend.options'] as $key => $option) { $memcached->setOption($key, $option); } } $memcachedStatus = $memcached->getVersion(); if (! is_array($memcachedStatus)) { throw new RuntimeException('No Memcached servers added.'); } if (in_array('255.255.255', $memcachedStatus) && count(array_unique($memcachedStatus)) === 1) { throw new RuntimeException('Could not establish Memcached connection.'); } return $memcached; }
?? ??? ????? ServiceProvider? ???? ??? ???? ???? ???. ??? ???? ??? ?????? ??? ?????. ??? ??????? ???? ?? ?? ???? ??? ???? ?? ?????.
??? '??'?? ??? ?????? ????? ?? ??? ???? ???, ??? ???, ???? ? ?? ??? ???? ??? ???? ?? ?????. ??? ???? ?????? ??? ?????.
Laravel? ?? ???? config/app.php ??? ?? ??? ??? ?????. ???? ???????? ??? ?? ??? ??? ???? ????. ?? ?? ? ???? ??? ??????. ?, ??? ??? ???? ?? ??? ??? ?? ?????.
?? ??? ???? IlluminateSupportServiceProvider ????? ?????. ???? ??? ?????? ?? ? ????? ? ?? ??? ????. ?? ????? ?? ? ?? ??? ????? ????? ?????. ??? ???, ?? ?? ?? ??? ????? ???? ????.
Artisan ?? make:provider:
php artisan make:provider MemcachedExtendServiceProvider
?? ??? ???? ??? ?? ?????. config/app.php ??. ? ???? ?? ??? ???? ??? ???? ??? ??? ???? ????. ????? ??? ??? ???? ??, ???, ?? ?? ?? Laravel ?? ?? ??? ?????.
??? ??? ????? ????? ?? ??? ?????.
'providers' => [ SmartWiki\Providers\MemcachedExtendServiceProvider::class // 在providers節(jié)點(diǎn)添加實(shí)現(xiàn)的provider ]
?? config/cache.php?? Memcached ??? ?????.
'MemcachedExtend' => [ 'driver' => 'MemcachedExtend', 'servers' => [ [ 'host' => env('MEMCACHED_EXTEND_HOST', '127.0.0.1'), 'port' => env('MEMCACHED_EXTEND_PORT', 11211), 'weight' => 100, ], ], 'options' => [ \Memcached::OPT_BINARY_PROTOCOL => true, \Memcached::OPT_COMPRESSION => false ] ]
?? ??? ??? ???? ?? ?? Session::extend? ???? ?? ???? ???? ???.
Session::extend('MemcachedExtend',function ($app){ $memcached = $this->createMemcached($app); return new MemcachedSessionHandler($memcached); });
?? ?? ??? ???? .env? ??? ? ????. ?? ??? ??? ????.
<?php namespace SmartWiki\Providers; use Illuminate\Cache\Repository; use Illuminate\Cache\MemcachedStore; use Illuminate\Support\ServiceProvider; use Cache; use Session; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler; use RuntimeException; class MemcachedExtendServiceProvider extends ServiceProvider { /** * Bootstrap the application services. * * @return void */ public function boot() { Cache::extend('MemcachedExtend', function ($app) { $memcached = $this->createMemcached($app); // 從配置文件中讀取緩存前綴 $prefix = $app['config']['cache.prefix']; // 創(chuàng)建 MemcachedStore 對象 $store = new MemcachedStore($memcached, $prefix); // 創(chuàng)建 Repository 對象,并返回 return new Repository($store); }); Session::extend('MemcachedExtend',function ($app){ $memcached = $this->createMemcached($app); return new MemcachedSessionHandler($memcached); }); } /** * Register the application services. * * @return void */ public function register() { // } /** * 創(chuàng)建Memcached對象 * @param $app * @return mixed */ protected function createMemcached($app) { // 從配置文件中讀取 Memcached 服務(wù)器配置 $servers = $app['config']['cache.stores.MemcachedExtend.servers']; // 利用 Illuminate\Cache\MemcachedConnector 類來創(chuàng)建新的 Memcached 對象 $memcached = new \Memcached; foreach ($servers as $server) { $memcached->addServer( $server['host'], $server['port'], $server['weight'] ); } // 如果服務(wù)器上的 PHP Memcached 擴(kuò)展支持 SASL 認(rèn)證 if (ini_get('memcached.use_sasl') && isset($app['config']['cache.storess.MemcachedExtend.memcached_user']) && isset($app['config']['cache.storess.MemcachedExtend.memcached_pass'])) { // 從配置文件中讀取 sasl 認(rèn)證用戶名 $user = $app['config']['cache.storess.MemcachedExtend.memcached_user']; // 從配置文件中讀取 sasl 認(rèn)證密碼 $pass = $app['config']['cache.storess.MemcachedExtend.memcached_pass']; // 指定用于 sasl 認(rèn)證的賬號密碼 $memcached->setSaslAuthData($user, $pass); } //擴(kuò)展 if (isset($app['config']['cache.stores.MemcachedExtend.options'])) { foreach ($app['config']['cache.stores.MemcachedExtend.options'] as $key => $option) { $memcached->setOption($key, $option); } } $memcachedStatus = $memcached->getVersion(); if (! is_array($memcachedStatus)) { throw new RuntimeException('No Memcached servers added.'); } if (in_array('255.255.255', $memcachedStatus) && count(array_unique($memcachedStatus)) === 1) { throw new RuntimeException('Could not establish Memcached connection.'); } return $memcached; } } SmartWikiCode

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

PHP?? ?? ??? ???? ? ?? ?? ??? ????. 1. php.ini? ?? ??? ??; 2. ? ?? (? : Apache? Setenv ?? nginx? FastCGI_Param)? ??????. 3. PHP ?????? putenv () ??? ??????. ? ??? Php.ini? ????? ??? ???? ??? ???? ? ?? ??? ?? ???? ????? ???? Putenv ()? ?? ??? ?????. ?? ???? ?? ?? (? : php.ini ?? ? ?? ??)? ???? ????. ?? ?? ??? ??? ?? ??? ????? ???? ?? ????.

Laravel? ?? ??? ?? ?? ??? ?? ?? ??? ???? ??? ??????. ?? ???? ?? ??? ????? ? ???? I/O ?? ? ?? ?? ??? ???? ???? ??? ?? ? ????. 1. ?? ????? ?? ? ? ???????? ??? ????? ?? ???? ??????. 2. ??? ? ??? ?? ? ? PhPartisAnconfig? ?? ???????. 3. ?? ??? ??? ??? ???? ?? ?? ?? ???? ???? ????. 4. ?? ?? ??? ???? ?? ??? ??? .env ??? ???? ?? ???????.

PHP ????? ?? ??? ??? ? ??? ??? CI (Continuous Integration) ????? ???? ? ????. 1. DockerFile? ???? ?? ???, ?? ??, ??? ?? ? ?? ??? ???? PHP ??? ?????. 2. Gitlabci? ?? CI/CD ??? ???? .gitlab-ci.yml ??? ?? ??, ??? ? ?? ??? ???? ?? ??, ??? ? ??? ?????. 3. PHPUNIT? ?? ??? ??? ??? ???? ?? ?? ? ???? ???? ????????. 4. Kubernetes? ?? ?? ?? ??? ???? ?? .yaml ??? ?? ?? ??? ?????. 5. Dockerfile ??? ? ??? ??? ??????

??? ?? ??? PHP ???? ?? ?? ??? ???? ?? ???????. RBAC (Role-Based Access Control) ??? ?? ???, ?? ? ??? ???? ??? ?? ?? ? ??? ?????. ?? ???? ??? ?????. 1. ???, ?? ? ??? ? ???? user_roles ? role_permissions? 3 ?? ?? ???; 2. $ user-> can ( 'edit_post')? ?? ???? ?? ?? ??? ?????. 3. ??? ???? ??? ??????. 4. ?? ??? ???? ?? ?? ?? ? ??? ? ???? ???? ?? ??? ? ?? ??? ?????. 5. ??? ??? ?? ?? ???? ?? ???? "??"? ??????.

Laravel? eloquentscopes? ?? ??? ??? ??? ?????? ?? ?? ??? ????? ?????. 1. ?? ??? ???? ???? ???? ???? Post :: published (); 2. ??? ??? ?? ??? ???? ???? ?? ??? ?? ?? ?? ??? ???? ???? ??? ?????? ??? ???? ???????. 3. ????? ?? ?? ?? ??? ??? ?? ?? ??? ?? ? ? ??? ?? ? ? ?? ?? ??? ?????. 4. ?? ??? ? ??? ?? ???? ? ??? ? ?? ??, ?? ??, ?? ???? ? ?? ?????????.

CreateAhelpers.phpfileInapp/helperswithCustOmFunctionsikeFormatPrice, isactiveroute, andisAdmin.2.addTheFileTothe "??"sectionOfcomposer.jsonUnderAutoLoad.3.runcomposerDump-AUTOLOADTOMAKETHINGTICTIONSGLOBELYAVAILABLE.4.USETHEHELPERFUNCUNTION

?? ?? ?? : ?? ????? PHP? ?? Error_Log ()? ??? ? ????. ????? ???? ??? ?? ??? ?????? ???? ?? ??? ? ?? ??? ???? ??? ?? ???, ??, ?? ? ?? ? ?? ?? ??? ???? ??? ??????. 2. ??? ?? ?? : ??? ??? ??? ??? ? ??? ?? ??? ??? ?? ??? ??? ??????? ??????. MySQL/PostgreSQL? ???? ??? ? ???? ??????. Elasticsearch Kibana? ? ???/? ???? ?????. ???, ??? ?? ? ??? ? ?? ??? ?? ??????. 3. ?? ? ?? ????? : ??, ???, ?? ? ??? ??? ??????. Kibana? ?? ????? PHP ??? ?? ?? ?????? ???? ???? ?????? ???? ??? ? ?? ??? ??? ? ????.

??, ??, ?? ?? ? ?? ??? ???? ?? ??? ?? ? ?? ???? ?????. 2. ?? ???? ???? ?? ??? ??? SONGSTOMONY ? HASMANY ?? ??; 3. ?? ? ? ?? ? ?? ??? ????? (?? ???? ?? ??? ? ??). 4. ?? ? ?? ??? ???? ?? ??? ???? ?? ? ?? ??? ???? ?? ??? ?????. 5. ?? ???? ??? ?? (?? ??)? ???? ?? ????? ??????. 6. ?? ??? ?? ??? ???? Laravel Signature URL? ???? ??? ??????. 7. ? ?? ?? ? ? ?? ??? ?? ?? ??? ?? ??? ?????. ?????? ??, ?? ?? ??? ??????????.
