PHP 编译安装 phpredis

cd ~/Downloads
git clone https://github.com/phpredis/phpredis.git
cd phpredis
/home/misswell/soft/php/bin/phpize
./configure --with-php-config=/home/misswell/soft/php/bin/php-config
make -j
make install

在 php.ini 里添加扩展

vim /home/misswell/soft/php/lib/php.ini

extension=redis

 

PHP7 源码编译安装 Swoole 扩展

cd ~/Downloads
git clone https://gitee.com/swoole/swoole.git
cd swoole
/home/misswell/soft/php/bin/phpize
./configure --with-php-config=/home/misswell/soft/php/bin/php-config
make -j
make install

或加上异步 redis

cd ~/Downloads 
git clone https://gitee.com/swoole/swoole.git
cd swoole 
/home/mi[......]

Read more

PHP Swoole 异步 redis 之 redis 服务安装

swoole 使用 异步redis的前置条件

  • redis 服务
  • hiredis库
  • 编译 swoole 需要加入 -enable-async-redis

安装 redis

下载 redis 地址: https://redis.io

cd ~/Downloads
tar -zxvf redis-4.0.9.tar.gz
cd redis-4.0.9
make

启动服务:

cd redis-4.0.9/src
./redis-server

hiredis 地址: https://github.com/redis/hiredis/releases[……]

Read more

Ubuntu16.04 PHP7 编译安装 PHP 扩展包 curl 安装记录

安装 PHP7.2.4 curl 扩展:

学习慕课网-Swoole入门到实战打造高性能赛事直播平台-7.9 章节时报错 undefined curl_init(),导致无法发送阿里大鱼短信,以下是报错信息

PHP Fatal error:  Uncaught Error: Call to undefined function Aliyun\Core\Http\curl_init() in /home/misswell/Code/thinkphp_5.1.0_rc/extend/ali/lib/Core/Http/HttpHelper.php:13

原因是缺少 curl 扩展[……]

Read more

PHP 封装一个 api 接口类

PHP 封装一个 api 接口类

使用:

$this->apiSuccess('返回成功', ['status'=>'1']);

返回结果:

{
    "info": "发布话题成功",
    "data": {
        "status": "1"
    },
    "code": 200
}

调用:

$this->apiError('返回失败');

返回结果:

{
    "info":"返回失败",
    "code":400
}

代码如下:

class RestController extends Cont[......]

Read more

PHP 中 json_encode() 的返回类型 JSON 数组和 JSON 对象

PHP 中 json_encode() 只将索引数组(indexed array)转为数组格式,而将关联数组(associative array)转为对象格式。

$arr = array(
    '0'=>'a','1'=>'b','2'=>'c','3'=>'d'
);
echo json_encode($arr);

结果是:

["a","b","c","d"]

而不是

{"0":"a","1":"b","2":"c","3":"d"}

强制转成对象

$arr = array(
    '0'=>'a','1'=>'b','2'=&[......]

Read more

PHP 判断当前地址是 HTTP 还是 HTTPS

$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$url = $http_type . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo $url;

另:打印 $_S[……]

Read more

Thinkphp 3.2.3 多表事务

$Model = M();
$Model->startTrans();
$userRes = $Model->table('test_user')->add(['name'=>'admin']);
$keyRes  = $Model->table('test_key')->add(['key'=>'test']);
$taskRes = $Model->table('test_task')->add(['task'=>'test']);
if (userRes && $keyRes && $t[......]

Read more

PHP 删除文件函数(清理缓存)

删除文件函数

function clean_cache($dirname='./Runtime/')
{
//清文件缓存
    $dirs = array($dirname);
//清理缓存
    foreach ($dirs as $value) {
        rmdirr($value);
    }
    @mkdir($dirname, 0777, true);
}

function rmdirr($dirname)
{
    if (!file_exists($dirname)) {
        return false;[......]

Read more

安装PHP出现make: *** [sapi/cli/php] Error 1 解决办法

ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor':
/home/king/php-5.2.13/ext/iconv/iconv.c:2491: undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
[root@test php-5.2.13]# vi Makefile

在安裝 PHP 到系统中时要是发生「undefined referenc[……]

Read more