分类目录归档:PHP

pecl update mongodb 1.1.* to 1.2.* 导致 php-fpm 全部立即段错误并失去控制,systemctl restart php-fpm失败

第二次遇到了~
ps -ef | grep php-fpm | cut -c 9-15 | xargs kill && systemctl restart php-fpm


Dec 15 20:40:02 web4 systemd: Removed slice User Slice of root.
Dec 15 20:40:02 web4 systemd: Stopping User Slice of root.
Dec 15 20:40:25 web4 kernel: traps: php-fpm[10171] general protection ip:7f4046d83120 sp:7ffc76043de0 error:0 in mongodb.so[7f4046d57000+be000]
Dec 15 20:40:25 web4 kernel: traps: php-fpm[1770] general protection ip:7f4054402542 sp:7ffc76045578 error:0 in ld-2.17.so[7f40543e9000+21000]
Dec 15 20:40:25 web4 kernel: traps: php-fpm[1771] general protection ip:7f4054402542 sp:7ffc76045578 error:0 in ld-2.17.so[7f40543e9000+21000]
Dec 15 20:40:25 web4 kernel: traps: php-fpm[1772] general protection ip:7f4054402542 sp:7ffc76045578 error:0 in ld-2.17.so[7f40543e9000+21000]
Dec 15 20:40:25 web4 kernel: traps: php-fpm[1773] general protection ip:7f4054402542 sp:7ffc76045578 error:0 in ld-2.17.so[7f40543e9000+21000]
Dec 15 20:40:25 web4 kernel: traps: php-fpm[1774] general protection ip:7f4054402542 sp:7ffc76045578 error:0 in ld-2.17.so[7f40543e9000+21000]
Dec 15 20:40:25 web4 kernel: traps: php-fpm[1775] general protection ip:7f4054402542 sp:7ffc76045578 error:0 in ld-2.17.so[7f40543e9000+21000]
Dec 15 20:40:25 web4 kernel: traps: php-fpm[1776] general protection ip:7f4054402542 sp:7ffc76045578 error:0 in ld-2.17.so[7f40543e9000+21000]
Dec 15 20:40:25 web4 kernel: traps: php-fpm[1777] general protection ip:7f4054402542 sp:7ffc76045578 error:0 in ld-2.17.so[7f40543e9000+21000]
Dec 15 20:40:25 web4 kernel: traps: php-fpm[1778] general protection ip:7f4054402542 sp:7ffc76045578 error:0 in ld-2.17.so[7f40543e9000+21000]
Dec 15 20:40:26 web4 systemd: Stopping LSB: starts php-fpm...

org.apache.solr.common.SolrException: Exception writing document id 663b167f2d661568 to the index; possible analysis error: cannot change DocValues type from SORTED_SET to NUMERIC for field “is_original”

org.apache.solr.common.SolrException: Exception writing document id 663b167f2d661568 to the index; possible analysis error: cannot change DocValues type from SORTED_SET to NUMERIC for field "is_original"

我这里修改tints类型为tint类型,导致新数据无法写入,字段删除完毕了,也reload了没有,只要清理的数据才行

<delete><query>*:*</query></delete>
<commit/>

Twig 快速集成

假设你的项目项目使用composer

1. 安装,为了兼容php5.4使用的是1.x版本

composer require twig/twig:~1.0

2. 封装为trait以集成

namespace objects\Traits;

trait DoufuTwig {

    /**
     * @var \Twig_Environment
     */
    private $twig;

    protected function renderTwig($path, $data = []) {
        if (! $this->twig) {
            $loader = new \Twig_Loader_Filesystem(APPPATH . 'views');
            $this->twig = new \Twig_Environment($loader, 
                array(
                    'cache' => APPPATH . 'cache',
                    'auto_reload' => true
                ));
        }
        
        return $this->twig->render($path, $data);
    }
}

3. 使用

集成到控制器父类

namespace Ncontrollers;

use objects\Traits\DoufuTwig;

abstract class Controller
{
    use DoufuTwig;
}

控制器内使用

...
echo $this->renderTwig('xxx/login.html');
...

奇异的setcookie无效问题

api.xxxx.com/aaa 页面下setcookie,

api.xxxx.com/xxx,cookie 有效

api.xxxx.com/index.php/xxx,cookie 无效

其实是cookie path的问题

setcookie($key, $value, null, ‘/’, null, null);

在框架外套一个路由器,单独处理部分请求

...前略

$_run_ci_ = false;

$_methods_ = 'GET|POST|PUT|DELETE|OPTIONS|PATCH|HEAD';

if (isset($_SERVER['REQUEST_METHOD']) &&
     in_array(strtoupper($_SERVER['REQUEST_METHOD']), explode('|', $_methods_))) {
    // Create Router instance
    $router = new \Bramus\Router\Router();
    
    # loader
    include APPPATH . 'hooks/doufu_autoload.php';
    $_doufu_loader_ = new doufu_autoload();
    $_doufu_loader_->run();
    
    // Define routes
    require_once dirname(__FILE__) . "/../../app/config/router.php";
    # default router
    $router->match($_methods_, '.*', function () use (&$_run_ci_) {
        $_run_ci_ = true;
    });
    
    // Run it!
    $router->run();
} else {
    $_run_ci_ = true;
}

if ($_run_ci_) {
    require_once BASEPATH . 'core/CodeIgniter.php';
}

路由器项目地址:https://github.com/bramus/router