Day: 2022年6月26日

Laravel 的 ORM 缓存包

LaraCache是一个基于 ORM 的 Laravel 包,用于基于模型查询创建、更新和管理缓存项。使用此包,您可以缓存在整个应用程序中大量使用的查询。

use Mostafaznv\LaraCache\Traits\LaraCache;
 
class Article extends Model
{
    use LaraCache;
 
    public static function cacheEntities(): array
    {
        return [
            CacheEntity::make('list.forever')
                ->cache(function() {
                    return Article::query()->latest()->get();
                }),
 
            CacheEntity::make('latest')
                ->validForRestOfDay()
                ->cache(function() {
                    return Article::query()->latest()->first();
                })
        ];
    }
}

使用该

                

PHP监控一个进程是否在运行的方法

PHP监控一个进程是否在运行的方法

 

exec("pgrep lighttpd", $pids);
if(empty($pids)) {

    // lighttpd is not running!
}

pgrep -f  全名匹配.

 

$mabbitmq=shell_exec("pgrep [r]abbitmq"); //https://stackoverflow.com/questions/51551908/why-is-the-result-equal-to-0-and-sometimes-1-shell-execpgrep-f
$mabbitmq = str_replace(PHP_EOL, '', $mabbitmq);
$mongodb=shell_exec("pgrep [m]ongo");
$mongodb = str_replace(PHP_EOL, '', $mongodb);
$ydmcuclient=shell_exec("pgrep -f [y]dmcu_client");
$ydmcuclient