高并发之后端优化(PHP)

页面静态化

使用模板引擎

可以使用Smarty的缓存机制生成静态HTML缓存文件

$smarty->cachedir=$ROOT·"/cache";//缓存目录
$smarty->caching=true;//是否开启缓存
$smarty->cachelifetime="3600";//缓存时间
$smarty->display(string template[,string cache_id[,string compile_id]]);
$smarty->clear_all_cache();//清除所有缓存
$smarty->clear_cache('file.html');//清除指定的缓存
$smarty->clear_cache('article.html',$art_id);//清除同一个模板下的指定缓存号的缓存

利用ob系列的函数

ob_start();//打开输出控制缓冲
ob_get_contents(); //返回输出缓冲区内容
0b_clean(); //清空输出缓冲区
0b_end_flush(); //冲刷出(送出)输出缓冲区内容井关闭缓冲

可以判断文件的inode修改时间,判断是否过期。

使用filectime函数

php并发处理

  1. PHP并发编程实践
  2. PHP的Swoole扩展
  3. 消息队列
  4. 接口的并发请求

常见消息队列产品
Kafka、ActiveMQ、ZeroMQ、RabbitMQ、Redis等

原文地址:https://www.cnblogs.com/qinsilandiao/p/10758082.html