背景:研究一下这个Swoole2.X(V2.0.8)的协程,于是试了一下Tcp/Mysql/Redis/Http(在一个以Http形式下,协程了:TcpServer配置、Redis配置、Mysql配置、Http,最后的接口返回时间以里面最长的那个为准,也就是一般是Mysql耗时最长,它就是最长的接口返回时间了。)一起上,Swoole顾问觉得要想性能高还得加上RPC,再就是在一些数据的Pack和Unpack性能上予以加强,以争取每个请求都非常快非常高效,一请求发现出现了段错误,最新版本出现小小的问题属于正常性况,关键是如何反馈问题,看了一下Swoole的Wiki是如何提Bug的连接,于是就试着提一个Bug吧,给其它用Swoole万一出现Coredump的兄弟们作一个示范,进行提Bug的和捕获相关的Coredump的输出,参考Swoole的Wiki,地址:https://wiki.swoole.com/wiki/page/10.html。

一、假如在你的项目中出现段错误,怎么办?重新编译打包Swoole的源码并打成RPm包,打开debug,参数是: --enable-debug ,如下:
swoole-php71-2.0.7.el7.x86_64.spec 打包./configure部分:
#./configure --with-php-config=%{php_bin}/php-config --enable-coroutine --enable-async-redis
./configure --with-php-config=%{php_bin}/php-config --enable-coroutine --enable-async-redis --enable-debug

二、Mysql部分做测试,加上用户权限,那个Tcp就用Swoole的示例打开9501端口,官网上有很简单的TcpServer样例(略),Mysql部分如下:
Mysql服务器上@101.200.*.135:
#mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 93109
Server version: 8.0.0-dmr-log Source distribution

mysql> grant all privileges on test.* to swooleUser@10.51.*.34 identified by "test123";
Query OK, 0 rows affected, 1 warning (0.04 sec)

mysql> flush privileges;    
Query OK, 0 rows affected (0.01 sec)

@测试机器@123.57.*.183
#rpm -ql mysql-client-8.0.0-170523211353.el7.centos.x86_64
/usr/local/mysql/bin/mysql
#/usr/local/mysql/bin/mysql -h10.44.*.177 -uswooleUser -p
Enter password:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.00 sec)



三、根据TcpServer配置、Redis配置、Mysql配置、Http(试着访问百度的Http页面),一般来讲都是Mysql慢,所以,它才是重点,代码如下:
coroutinemysql.php

<?php
$server = new Swoole\Http\Server("123.57.*.183", 9507, SWOOLE_BASE);
$server->set([
    'worker_num' => 1,
]);

$server->on('Request', function ($request, $response) {
    $tcpclient = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
    $tcpclient->connect('127.0.0.1', 9501,0.5);
    $tcpclient->send("hello world\n");

    $redis = new Swoole\Coroutine\Redis();
    $redis->connect('123.57.*.183', 6379);
    $redis->setDefer();
    $redis->get('key');

    $mysql = new Swoole\Coroutine\MySQL();
    $ret = $mysql->connect([
    'host' => '10.44.*.177',
    'port' => 3306,
        'user' => 'swooleUser',
        'password' => 'test123',
        'database' => 'test',
    ]);
    if ($ret == false) {
        $response->end("MySQL connect fail!");
        return;
    }
    $mysql->setDefer();
    $mysql->query('select sleep(1)');

    $httpclient = new Swoole\Coroutine\Http\Client('123.125.114.144', 80);
    $httpclient->setHeaders(['Host' => "baidu.com"]);
    $httpclient->set([ 'timeout' => 1]);
    $httpclient->setDefer();
    $httpclient->get('/');

    $tcp_res  = $tcpclient->recv();
    $redis_res = $redis->recv();
    $mysql_res = $mysql->recv();
    $http_res  = $httpclient->recv();

    $response->end('Test End');
});
$server->start();




四、按Swoole官方的Wiki教程,设置一下吐核,From: https://wiki.swoole.com/wiki/page/10.html :
#ulimit -c unlimited

五、启动对外提供的Http协议的9507端口访问进来后的多种协议并发的协程服务,如下:
#php  coroutinemysql.php


六、访问Http时再触发一下协程:
触发一下:http://123.57.*.183:9507/

七、生成了段错误的Coredump文件,如下:
#php  coroutinemysql.php
段错误(吐核)

#ls *core*              
core.8494


八、用GDB去跟进其堆栈,BT显示调用层级定位出现问题所在位置:
#gdb php /tmp/core.8494
(gdb) bt
#0  0x00007f146b33e9a5 in http_client_coro_send_http_request (zobject=0x7f147248d190)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/swoole_http_client_coro.c:501
#1  0x00007f146b383c93 in swClient_onWrite (reactor=<optimized out>, event=0x7ffd0c185a10)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/Client.c:1109
#2  0x00007f146b37d63c in swReactorEpoll_wait (reactor=0x1dfc338, timeo=<optimized out>)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/reactor/ReactorEpoll.c:270
#3  0x00007f146b389de9 in swReactorProcess_loop (pool=<optimized out>,
    worker=worker@entry=0x7ffd0c185ae0)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/ReactorProcess.c:379
#4  0x00007f146b38a727 in swReactorProcess_start (serv=serv@entry=0x1dc7cf0)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/ReactorProcess.c:112
#5  0x00007f146b381538 in swServer_start (serv=serv@entry=0x1dc7cf0)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/Server.c:696
#6  0x00007f146b333730 in zim_swoole_http_server_start (execute_data=0x7f14724130a0,
    return_value=0x7ffd0c185cb0)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/swoole_http_server.c:1567
#7  0x00000000008ad0c6 in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER ()
#8  0x000000000085bd3b in execute_ex ()
#9  0x00000000008aee24 in zend_execute ()
#10 0x0000000000816fc4 in zend_execute_scripts ()
#11 0x00000000007b8520 in php_execute_script ()
#12 0x00000000008b0fbf in do_cli ()
#13 0x000000000043d450 in main ()

(gdb)f 1
#1  0x00007f146b383c93 in swClient_onWrite (reactor=<optimized out>, event=0x7ffd0c185a10)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/Client.c:1109
1109                cli->onConnect(cli);

(gdb)f 0
#0  0x00007f146b33e9a5 in http_client_coro_send_http_request (zobject=0x7f147248d190)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/swoole_http_client_coro.c:501
501         if (!http->cli || !http->cli->socket )

九、用valgrind大体排查一下是否有内存溢出等:
[root@测试服务器:/tmp]
#USE_ZEND_ALLOC=0 valgrind php coroutinemysql.php
==12833== Memcheck, a memory error detector
==12833== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==12833== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==12833== Command: php coroutinemysql.php
==12833==

==12833== Invalid read of size 8
==12833==    at 0x121249A5: http_client_coro_send_http_request (swoole_http_client_coro.c:501)
==12833==    by 0x12169C92: swClient_onWrite (Client.c:1109)
==12833==    by 0x1216363B: swReactorEpoll_wait (ReactorEpoll.c:270)
==12833==    by 0x1216FDE8: swReactorProcess_loop (ReactorProcess.c:379)
==12833==    by 0x12170726: swReactorProcess_start (ReactorProcess.c:112)
==12833==    by 0x12167537: swServer_start (Server.c:696)
==12833==    by 0x1211972F: zim_swoole_http_server_start (swoole_http_server.c:1567)
==12833==    by 0x8AD0C5: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (in /usr/local/php/bin/php)
==12833==    by 0x85BD3A: execute_ex (in /usr/local/php/bin/php)
==12833==    by 0x8AEE23: zend_execute (in /usr/local/php/bin/php)
==12833==    by 0x816FC3: zend_execute_scripts (in /usr/local/php/bin/php)
==12833==    by 0x7B851F: php_execute_script (in /usr/local/php/bin/php)
==12833==  Address 0x100000188 is not stack'd, malloc'd or (recently) free'd
==12833==
==12833==
==12833== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==12833==  Access not within mapped region at address 0x100000188
==12833==    at 0x121249A5: http_client_coro_send_http_request (swoole_http_client_coro.c:501)
==12833==    by 0x12169C92: swClient_onWrite (Client.c:1109)
==12833==    by 0x1216363B: swReactorEpoll_wait (ReactorEpoll.c:270)
==12833==    by 0x1216FDE8: swReactorProcess_loop (ReactorProcess.c:379)
==12833==    by 0x12170726: swReactorProcess_start (ReactorProcess.c:112)
==12833==    by 0x12167537: swServer_start (Server.c:696)
==12833==    by 0x1211972F: zim_swoole_http_server_start (swoole_http_server.c:1567)
==12833==    by 0x8AD0C5: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (in /usr/local/php/bin/php)
==12833==    by 0x85BD3A: execute_ex (in /usr/local/php/bin/php)
==12833==    by 0x8AEE23: zend_execute (in /usr/local/php/bin/php)
==12833==    by 0x816FC3: zend_execute_scripts (in /usr/local/php/bin/php)
==12833==    by 0x7B851F: php_execute_script (in /usr/local/php/bin/php)
==12833==  If you believe this happened as a result of a stack
==12833==  overflow in your program's main thread (unlikely but
==12833==  possible), you can try to increase the size of the
==12833==  main thread stack using the --main-stacksize= flag.
==12833==  The main thread stack size used in this run was 8388608.
==12833==
==12833== HEAP SUMMARY:
==12833==     in use at exit: 22,357,752 bytes in 22,711 blocks
==12833==   total heap usage: 29,852 allocs, 7,141 frees, 23,257,973 bytes allocated
==12833==
==12833== LEAK SUMMARY:
==12833==    definitely lost: 64 bytes in 2 blocks
==12833==    indirectly lost: 4,096 bytes in 2 blocks
==12833==      possibly lost: 1,813,286 bytes in 18,399 blocks
==12833==    still reachable: 20,540,306 bytes in 4,308 blocks
==12833==         suppressed: 0 bytes in 0 blocks
==12833== Rerun with --leak-check=full to see details of leaked memory
==12833==
==12833== For counts of detected and suppressed errors, rerun with: -v
==12833== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
段错误


十、在PHP代码上加加减减,定位一下PHP这个协程是哪个协议出现问题,经定位发现是发起http这块的协程可能有问题,如下:
再细节一点:
#php coroutinemysql.php
段错误(吐核)
这一行引起的:$httpclient->setDefer();     #setDefer函数的Wiki地址:https://wiki.swoole.com/wiki/page/607.html

$httpclient = new Swoole\Coroutine\Http\Client('123.125.114.144', 80);
$httpclient->setHeaders(['Host' => "baidu.com"]);
$httpclient->set([ 'timeout' => 3]);
$httpclient->setDefer();            #注释这一行,就会报下面的警告,不会Coredump,如下:                                                                
$httpclient->get('/');

#php coroutinemysql.php   #浏览器访问一下:http://123.57.*.183:9507/
PHP Warning:  Swoole\Coroutine\Http\Client::recv(): you should not use recv without defer  in /tmp/coroutinemysql.php on line 40
PHP Warning:  Swoole\Coroutine\Http\Client::recv(): you should not use recv without defer  in /tmp/coroutinemysql.php on line 40

在服务器上CURL形式访问一下百度,没毛病:
curl -i -H"Host:baidu.com" http://123.125.114.144            
HTTP/1.1 200 OK  
<html>
<meta http-equiv=refresh content=0;url=http://www.baidu.com/>
</html>


十一、提交出现Coredump以及和环境相关的问题给Swoole的CoreTeam研发小组的兄弟:
请将上面的得到的信息,连同机器信息,包括php -v gcc -v uname -a 提交到Github Issues页面或者发送邮件到 team@swoole.com。
若确定是Swoole的问题,开发组会快速解决问题。
其它涉及到编译器和PHP版本、系统环境:
#php -v
PHP 7.1.5 (cli) (built: May 23 2017 10:35:57) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.5, Copyright (c) 1999-2017, by Zend Technologies

#gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)


#uname -a
Linux 测试服务器 4.11.2-1.el7.elrepo.x86_64 #1 SMP Sun May 21 19:31:34 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux


#php --ri swoole

swoole

swoole support => enabled
Version => 2.0.8
Author => tianfeng.han[email: mikan.tenny@gmail.com]
epoll => enabled
eventfd => enabled
timerfd => enabled
signalfd => enabled
cpu affinity => enabled
spinlock => enabled
rwlock => enabled
async redis client => enabled
async http/websocket client => enabled
Linux Native AIO => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled

Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.fast_serialize => 1 => 1
swoole.unixsock_buffer_size => 8388608 => 8388608


EOF
背景:发现df 特别慢,用strace df -h ,发现卡在/mnt/backup,想cd /mnt卡住了,于是,怎么办?发现NFS的Server端都宕机了。
cat /proc/mounts
umount -lf   /mnt/backup
umount: only root can do that
Root:
umount -lf   /mnt/backup
More: http://justwinit.cn/post/6800/
-------------------------------------------------------------------------------------
这个问题是第二次遇到了。这次一定要记下来,免得日后麻烦!!
问题描述:

有两台服务器,其中一台向另一台通过nfs共享分区,如下:

server A: nfs server
server B: nfs Client

事件发生: Server A,B 因故障同时重启。 重启后,用putty登陆到server A ,运行‘df’命令:
$ df

$ Filesystem           1K-blocks      Used Available Use% Mounted on

/dev/sda5             80632188   8899080  67636940  12% /

none                   4086484         0   4086484   0% /dev/shm

/dev/sda2            201582252  32076524 159265900  17% /opt

/dev/sda3            201582252  44511180 146831244  24% /fs

/dev/sda7             20161172    332916  18804116   2% /usr/local

/dev/sda8             20161172     78360  19058672   1% /tmp

$(没有出现这个命令提示符)

无奈,只好再用putty 登陆Server A ,将 df 进程kill......


只好尝试重新mount

$mount -t nfs B:/data /mnt/data

failed: RPC Error: Program not registered


哦~~~ ,原来B的nfs 服务没有start...  登陆B:
$serive nfs restart

重新再A上运行df,仍然死掉...

想到先卸载,在挂载:

$umount /mnt/data

device is busy 。



运行fuser -mk /mnt/data 杀掉访问/mnt/data所有进程。

/mnt/data: Stale NFS file handle



在server A 运行 A , ok ~~~

重新mount -t nfs B:/data /mnt/data  打完收工。

来自:http://blog.csdn.net/daniel_cao_/article/details/4584443
TPLink_TLWN725N无线网卡支持SoftAP功能,在XP下面配置模拟AP时,开启SoftAP功能,
可能会弹出报错信息“配置ICS失败,你可以连接到SoftAP,但可能无法使用因特网服务”。
解决方法:
1.电脑上打开“服务与应用程序”---“服务”,找到“Windows Firewall/Internet Connection Sharing(ICS)”服务,确保此服务已经开启,如未开启,将此服务手动开启并将启动类型设置为自动。

2.如果电脑上网络连接在开启SoftAP之前就已经手动共享过了,将此共享取消。

3.如果电脑上网络连接在开启SoftAP之前并没有手动共享过,但是仍然提示错误,很有可能是电脑的系统在开启SoftAP功能之前曾经使用过网络连接共享的应用,其状态尚未恢复到初始状态。首先关闭SoftAP功能。接着打开电脑网络连接页面,找到本地连接,查看本地连接状态是否已经共享。
(1)若已经共享,右键“本地连接”选择“属性”---“高级”选项卡,将“Internet连接共享”关闭,点击“确定”。然后将另外一个网络连接的共享开启之后再关闭。重新尝试开启SoftAP功能。
(2)若未共享,随便找一个网络连接,将其共享开启之后再关闭,然后重新尝试开启SoftAP功能。


来自:http://www.360doc.com/content/13/1010/18/2250352_320378101.shtml

http://callmepeanut.blog.51cto.com/7756998/1302958
https://huoding.com/2013/10/06/288
检查是否安装了libxm包

[root@rh-Linux software]# rpm -qa |grep libxml2
libxml2-2.7.6-21.el6_8.1.x86_64
libxml2-devel-2.7.6-21.el6_8.1.x86_64
libxml2-python-2.7.6-21.el6_8.1.x86_64
重新安装libxml2和libxml2-devel包, yum安装的时候发现新版本会提示更新,需要更新的可以更新,不要跳过就行了。

[root@rh-linux /]# yum install libxml2
[root@rh-linux /]# yum install libxml2-devel -y
安装完之后查找xml2-config文件是否存在

[root@rh-linux /] #find / -name "xml2-config"
/usr/bin/xml2-config

From:http://blog.csdn.net/risingsun001/article/details/43705273
背景:在工作中经常会遇到一些关于定时任务的实际场景,比如每天凌晨1点自动备份数据库,或者,每隔1小时执行一次爬虫脚本,这种固定时间执行固定动作的需求我们称之为定时任务,利用crontab即可轻松实现。如果我们对自动备份数据库这个定时任务改变一下需求(这种情况就像你邀请一个人,一天内如果没有人来或有人来你通知下你,你邀请的人来了,这种任务。二、再就是公司没啥好的设备,钱少,网太烂了搞一个任务比如Mysql备份数据库的脚本,比如备份Redis的数据Bgsave的Scp拷贝经常出现网络不好,第一次备份会失败,于是得第二次这种垃圾需求。有垃圾需求就有解决办法,于于优雅或不优雅是一回事,但得技术人员觉得有一个流程总比没有流程好,本来没有方案的,于是就有技术方案。),如图:
点击在新窗口中浏览此图片  
如果仍然利用crontab来实现,就有点勉强了。类似这种需求最常见的是服务器之间的消息通知,假如服务器B由于网络不稳定或者服务器压力较大导致不能即时对服务器A的消息作出正确响应,那么服务器A就会延迟一段时间再次发送消息,直到收到服务器B的正确响应或者超出最大通知次数为止。过去的做法是定时扫表,把通知失败的消息再次发送一遍,虽然可以多次发送通知,但是发送间隔太短会增加服务器B的压力,发送间隔太长消息的时效性就不能保证,显然处理这种延时任务用crontab根本不能解决问题。
Node之Error: Cannot find module 'redis:
#npm install -g redis
/usr/lib
└─┬ redis@2.7.1
  ├── double-ended-queue@2.1.0-0
  ├── redis-commands@1.3.1
  └── redis-parser@2.6.0
环境变量:
#rpm -ql nodejs-6.10.3-1.el7.x86_64
/usr/bin/node
/usr/lib/node_modules
export NODE_PATH=/usr/lib/node_modules
#echo $NODE_PATH  
/usr/lib/node_modules
#node notice.js
订阅成功

select 3
OK
setex msg_2 2 chokingwin
OK
client.on("pmessage", function(pattern, channel, expiredKey) {
    console.log(pattern + "|" + channel + "|" + expiredKey);
_             _keyevent@3__:expired|__keyevent@3__:expired|msg_2




从Redis 2.8.0版本起,加入了"Keyspace notifications"(即"键空间通知")的功能。按照官方的说法:键空间通知,允许Redis客户端从“发布/订阅”通道中建立订阅关系,以便客户端能够在Redis中的数据因某种方式受到影响时收到相应事件。比如:所有改变给定key的命令;所有经过lpush操作的key;所有在0号数据库中过期的key等等。我们在处理延时任务的时候,先把通知失败的消息ID作为key的一部分存到redis缓存中,并设定过期时间(相当于延时),当这条缓存数据失效的时候,通过订阅关系(用NodeJS实现)就可以收到消息,通过分析消息就可以知道过期KEY,这样就可以再次发送消息通知,从而实现延时任务。
不过,需要注意一点:Redis的发布/订阅目前是即发即弃(fire and forget)模式的,因此无法实现事件的可靠通知。也就是说,如果发布/订阅的客户端断链之后又重连,则在客户端断链期间的所有事件都丢失了。
核心部分是两个Redis的终端,分别连接上Redis,并打开这个特性,另一个终端是监控的,这块里面用代码进行编写订阅,如下:
订阅,作者用的是Node,我在这儿不得不打下广告了,Swoole是不是应该也能支持这个功能?https://wiki.swoole.com/wiki/page/523.html ,http://blog.csdn.net/koastal/article/details/52869140,subscribe。
psubscribe来自:https://wiki.swoole.com/wiki/page/590.html

<?php
$serv = new Swoole\Server("127.0.0.1", 9501);
$serv->set(array(
    'worker_num' => 8,   //工作进程数量
    'daemonize' => false, //是否作为守护进程
));
$serv->on('connect', function ($serv, $fd){
    echo "Client:Connect.\n";
});
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
    $val = "";
    $redis = new Swoole\Coroutine\Redis();
    $redis->connect('10.51.77.34', 6379);
    while (true) {
        $val = $redis->psubscribe(['psubscribe __keyevent@3__:expired']);
        //订阅的channel,以第一次调用subscribe时的channel为准,后续的subscribe调用是为了收取Redis Server>的回包
        //如果需要改变订阅的channel,请close掉连接,再调用subscribe
        var_dump($val);
    }                                                                                                    
});
$serv->on('close', function ($serv, $fd) {
    echo "Client: Close.\n";
});
$serv->start();


Swoole的这个Redis的Coroutine必须要有一个端口暴露,这是和Node最大的不同吧?上面这个图我试着使用了一下,感觉有点问题。
=============================================================================

#redis-cli -h 10.51.77.34
10.51.77.34:6379>  psubscribe __keyevent@0__:expired
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "__keyevent@0__:expired"
3) (integer) 1



1) "pmessage"
2) "__keyevent@0__:expired"
3) "__keyevent@0__:expired"
4) "name"



塞一个数据进去:

#redis-cli -h 10.51.77.34
10.51.77.34:6379> config set notify-keyspace-events Ex
OK
10.51.77.34:6379> setex name 10 chokingwin
OK


===================================================================================
关于expired事件通知的发送时间
Redis使用以下两种方式删除过期的键:a:当一个键被访问时,程序会对这个键进行检查,如果键已过期,则删除该键;b:系统会在后台定期扫描并删除那些过期的键。
当过期键被以上两种方式中的任意一种发现并且删除时,才会产生expired事件通知。
Redis不保证生存时间(TTL)变为 0 的键会立即被删除:如果没有命令访问这个键,或者设置生存时间的键非常多的话,那么在键的生存时间变为0,到该键真正被删除,这中间可能会有一段比较显著的时间间隔。
因此,Redis产生expired事件通知的时间,是过期键被删除的时候,而不是键的生存时间变为 0 的时候。
接下来我们开始代码实现(假定阅读本文的同学已正确安装Nginx/PHP/Redis/NodeJS的环境)。

一、与本文相关的环境信息
Redis配置文件路径:/etc/redis/6379.conf
测试用的Redis库编号为:3
监听消息的NodeJS文件:/NodeApp/notice.js
发送消息的PHP代码为:/send.php
接收redis数据的PHP代码:/test.php
业务流程:首先运行notice.js开启监听,然后运行send.php发送消息,如果没有收到成功响应,将消息ID存入redis缓存,之后按照10秒、30秒、60秒、120秒、300秒的时间间隔,再次发送消息通知,直到收到对消息的成功响应,或者超出最大通知次数为止。

二、修改Redis配置文件
因为键空间通知功能需要耗费一定的CPU时间,因此默认情况下,该功能是关闭的。可以通过修改配置文件,或者通过CONFIG SET命令,设置notify-keyspace-events选项,来启用或关闭该功能。
该选项的值为空字符串时,该功能禁用,选项值为非空字符串时,启用该功能,非空字符串由特定的多个字符组成,每个字符表示不同的意义:
K keyspace事件,事件以__keyspace@<db>__为前缀进行发布
E keyevent事件,事件以__keyevent@<db>__为前缀进行发布
g 一般性的,非特定类型的命令,比如del,expire,rename等
$ 字符串特定命令
l 列表特定命令
s 集合特定命令
h 哈希特定命令
z 有序集合特定命令
x 过期事件,当某个键过期并删除时会产生该事件
e 驱逐事件,当某个键因maxmemore策略而被删除时,产生该事件
A g$lshzxe的别名,因此”AKE”意味着所有事件
注意:该选项的值中至少需要包含K或者E,否则不会发布任何事件。比如,如果需要开启针对列表的keyspace事件通知,则该选项需要配置为"Kl"。

我们在服务器上运行vim /etc/redis/6379.conf,找到notify-keyspace-events开头的一行,将其配置为:notify-keyspace-events Ex,含义为:发布keyevent事件,使用过期事件(当每一个key失效时,都会生成该事件)。保存退出,并重启redis服务。如图:
点击在新窗口中浏览此图片

三、安装Node扩展
在网站根目录下,依次运行:
npm init #初始化创建package.json
npm install redis #安装redis扩展
npm install mysql #安装mysql扩展

四、实现send.php

为了便于实现延时的计算,我们将存入redis的key格式设计为:固定前缀+消息ID+时间戳+次数,如:noticeId_12345678_1482991887_2点击在新窗口中浏览此图片
关键代码:
$delayArr=[0,10,30,60,120,300];//延时间隔,相对于首次通知时间,单位为 s
$res=doSomething();//发送消息
$content=date('Y-m-d H:i:s').' 第 '.$nums.' 次发送通知,消息ID为:'.$noticeId."\n";
if($res==true){
$content.='消息发送成功'."\n";
}else{//未收到对方回应
$content.='消息发送失败,等待下次重发'."\n";
$expTime=$delayArr[$nums];
$nums++;
saveNoticeToRedis($noticeId,$stamp,$nums,$expTime);//存入缓存
}
//记录日志
file_put_contents($root.'/tmp.log',$content,FILE_APPEND);

五、实现 notice.js
服务器端运行notice.js后,会一直监听redis的Expired事件,取到ExpiredKey后,把消息ID、时间、通知次数,POST给test.php,从而实现再次发送消息。

关键代码:
var client = redis.createClient('6379', '127.0.0.1');
client.psubscribe("__keyevent@"+redisDB+"__:expired",function(){
//console.log('订阅成功');
});
client.on("pmessage", function(pattern, channel, expiredKey) {
var tmpArr=expiredKey.split('_');
if(tmpArr[0]==keyPrefix){
console.log('-----expired Key-----',expiredKey);
var noticeId=tmpArr[1];
var stamp=parseInt(tmpArr[2]);
var nums=parseInt(tmpArr[3]);
sendPost(noticeId,stamp,nums,logFile);//向test.php发送数据
}else{
console.log('-----error Key-----',expiredKey);
writeLog(logFile,'The key "'+expiredKey+'" is a error key.');
}
});

六、实现 test.php
点击在新窗口中浏览此图片

关键代码:

$delayArr=[0,10,30,60,120,300];//延时间隔,相对于首次通知时间,单位为 s
$res=doSomething();//发送消息
$content=date('Y-m-d H:i:s').' 第 '.$nums.' 次发送通知,消息ID为:'.$noticeId."\n";
if($res==true){
$content.='消息发送成功'."\n";
}else{//未收到对方回应
if($nums && $nums>=6){
$content.='消息ID:'.$noticeId."已达到最大通知次数,任务停止\n";
}else{
$content.='消息发送失败,等待下次重发'."\n";
$expTime=$stamp+$delayArr[$nums]-time();
$nums++;
saveNoticeToRedis($noticeId,$stamp,$nums,$expTime);//存入缓存
}
}
//记录日志
file_put_contents($root.'/tmp.log',$content,FILE_APPEND);

七、测试结果
点击在新窗口中浏览此图片

八、其他说明
本文内容为个人原创,首发今日头条,同时提供代码下载地址,供大家学习交流。本人以后还会发布更多原创干货,如果觉得有用,希望及时关注本头条号。

代码下载地址:http://www.i1981.com/zb_users/upload/2016/12/20161223.zip
DownLoad:
下载文件
点击这里下载文件


From: http://www.toutiao.com/a6369425996433408257/?tt_from=weixin&utm_campaign=client_share&app=news_article&utm_source=weixin&iid=11032449540&utm_medium=toutiao_ios&wxshare_count=1
背景:Node和PHP在IO密集型上的一个探讨,IO密集可能Node要好一点,能更多压榨系统性能。这个链接应该有一定向Node的倾向性,但都看看叫兼听则明嘛。
Q:兄弟用Node搞毛,赶紧竹筒倒豆子,呵呵
A:做接入层啊,替代PHP接入层的角色.异步嘛 PHP同步是短板

Q:哪些函数异步了?函数支持异步才行吧,要是同步函数不也是同步嘛。
A:nodejs本身天然就支持异步的,里面的所以IO操作都是天然就是异步的。

Q:PHP vs NODE:喔,像兄弟们主要用的Mysql和那个Redis啥的接口吧,还有啥?
A:看场景,如果IO多的话,并发性能能高很多:http://taobaofed.org/blog/2015/11/24/nodejs-php-process-manager/

Q:说白了就是把Node当PHP用呗,IO密集有奇效?
A:是的
php安装模块见http://fffo.blog.163.com/blog/static/211913068201401464238334/

1、官网下载
wget http://prdownloads.sourceforge.net/lam/ldap-account-manager-4.3.tar.bz2?download
2、解压
tar -xjf  ldap-account-manager-4.3.tar.bz2
3、直接移动到apache 根目录
mv  ldap-account-manager-4.3 /usr/local/apache/htdocs/lam
4、给它可以访问的权限
chmod 777 -R /usr/local/apache/htdocs/lam
5、进入配置目录
cd /usr/local/apache/htdocs/lam/config
6、创建主参数文件
cp config.cfg_sample config.cfg
7、创建连接ldap服务器参数文件
cp lam.conf_sample lam.conf
vim lam.conf
修改 所有的dc=1v,dc=cn
8、web访问
http://203.195.187.200/lam/templates/login.php

上面的模式是只限管理员登录模式。现在切换到用户登录模式
点击LAM配置——>编辑服务器配置文件——>默认密码是lam(可修改)——>通用设置——>安全设定

From:http://blog.csdn.net/u012461550/article/details/42608781

我的是在:
/usr/local/lam/etc/unix.conf
一、旧版本的PHP(php5.3.27)要装Mysql之后才能装Mysql(mysqli)扩展?编译选项有这个:
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config

传统的安装php的方式中,我们在编译PHP时,一般需要指定以下几项:
--with-mysql=/usr/local/mysql
--with-pdo-mysql=/usr/local/mysql
这实际上就是使用了mysql官方自带的libmysql驱动, 这是比较老的驱动, PHP 5.3开始已经不建议使用它了, 而建议使用mysqlnd.


以上是摘录,更多查看:http://blog.163.com/yxba_02/blog/static/187557620160401018458/


二、PHP7啥的都不用指定Mysql的位置,直接就能编译通过的呀~

PHP7这样的:
--with-mysql=mysqlnd \    
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \

现在系统存在历史问题,没法一时半会升级PHP7了,还在用 php5.3.27上混,编译选项有指定Mysql路径的。
ldd php
发现:
libmysqlclient.so.18 => /usr/lib64/libmysqlclient.so.18 (0x00002b5b5dec7000)
也就是说PHP5.3.7最后还是编译成自己的LIb了,没有Mysql一样能跑,这TM是个问题,装个PHP还得装上Mysql,这个低版本的PHP还得装Mysql服务才行哟。

总之,Mysql和PHP在低版本有了较强的捆绑,而新的PHP7采用Mysqlnd(MySQL Native Driver),摆脱了这一依赖,更简单,更高效。php高版本不再使用mysql_connect()来连接数据库。

背景:一般来讲Linux对明文登录用户的密码在CentOS里有多种,但是MD5长度在36位以下。容量被破解,正向算法、碰撞等,特别是那个万能Wifi钥匙,我去。CentOS5和CentOS6的想法是更安全,但为了兼容统一管理密码Shadow,批量刷一样的,往往会用MD5这种方式,但是被破解后也是很容易给被攻下的一种弱的加密验证方式。
当用户发出useradd命令时,useradd命令读取/ etc / default / useradd和/etc/login.defs并确定useradd的默认值。 要显示/ etc / defaults / useradd的值,请参阅显示useradd的默认值

#使用MD5或DES加密密码? 红帽默认使用MD5。
MD5_CRYPT_ENAB是的

ENCRYPT_METHOD MD5

背景:原来是因为Jenkins的组不对,再把组修正了下,再加上chmod a+s /bin/su ,后来发现是因为/etc/passwd 里面的shell是 :/bin/false导致没法sudo 成功。
su jenkins
id
uid=0(root) gid=0(root) 组=0(root)

试了下Su到其它用户可以,于是查了一下 vi /etc/passwd :
jenkins:x:1012:1010:Jenkins Continuous Integration Server:/data/jenkins:/bin/false
原来是这儿/bin/false,不是su的问题:
jenkins:x:497:601:Jenkins Continuous Integration Server:/data/jenkins:/bin/bash

于是就好了:
[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# su jenkins
[jenkins@iZ2zehnf4lbq2wf83bmzk1Z root]$ id
uid=1012(jenkins) gid=1010(jenkins) 组=1010(jenkins)
==================================================

[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# su jenkins
[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# id
uid=0(root) gid=0(root) 组=0(root)
[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# whoami
root
[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# id jenkins
uid=984(jenkins) gid=990(jenkins) 组=990(jenkins)

========================================
原因1
/bin/su文件没有s位权限


chmod a+s /bin/su


来自:http://blog.itpub.net/26432034/viewspace-1688391/

解决办法
感谢csdn用户jeecg-scott分享的博文《su 切换,提示:“密码不正确”》以下是连接
http://blog.csdn.net/zhangdaiscott/article/details/18666471

step1
检查/etc目录下passwd的权限
[root@dev /]# ll /etc/passwd
-rw-r--r--. 1 root root 1975 5月  27 06:04 /etc/passwd
如果普通用户不能读请改成644权限
[root@dev /]# chmod 644 /etc/passwd

step2
检查/bin/su文件是否有s位权限
[root@dev ~]# ll /bin/su
-rwxrwxrwx. 1 root root 34904 10月 17 2013 /bin/su
如果不存在则添加上
[root@dev /]# chmod a+s /bin/su
[root@dev /]# ll /bin/su
-rwsrwsrwx. 1 root root 34904 10月 17 2013 /bin/su

step3
测试成功否
[oracle@dev ~]$ su - root
密码:
[root@dev ~]#

ls  -lart /data/redis6413 |less
-rw-r--r--  1 redis redis 211841024 Jan  9 14:00 temp-33345.rdb
-rw-r--r--  1 redis redis 212078592 Jan  9 15:00 temp-53462.rdb
-rw-r--r--  1 redis redis 220446720 Jan  9 16:00 temp-8399.rdb
-rw-r--r--  1 redis redis 212865024 Jan  9 17:00 temp-28516.rdb

http://blog.csdn.net/opens_tym/article/details/10097805
背景:听说Lumen起家是以一个叫av的框架,larvael。以Auth2.0起步,Lumen是精简版本,于是想了解一下。发现居然边TM路由就卡住了,Fuck,不光是我老外也有这个问题,都没有解决,主要是一个Nginx的转写问题,这块在Lumen的文档里写的很垃圾,我都不知这些人是怎么写文档的,有用Apache,有Nginx的就不能写细一点么,说一下原理啥的,关键是Nginx配置文件里面的:location /里面的重写。
From:http://blog.csdn.net/wowkk/article/details/52104689
路由:https://lumen.laravel.com/docs/5.4
中文文档:http://laravelacademy.org/laravel-docs-5_4
5.4这个路由,老外写得很简单,这帮人可能是想你去看他的代码吧,有很多人在问:
http://www.thinksaas.cn/ask/question/22000/

做微服务:/usr/local/nginx/conf/vhosts/ms.conf

server_name  10.70.**.142;
root /data/www/ms/;
rewrite ^/(survey)/.*$ /$1/public/index.php last;
http://10.70.33.140/survey/public/index.php
/data/www/ms/survey/public/index.php
======================================================

/usr/local/composer/composer.phar  global require "laravel/lumen-installer"
https://lumen.laravel.com/docs/5.4#server-requirements 下面的:
chmod a+x /root/.config/composer/vendor/laravel/lumen-installer/lumen
/root/.config/composer/vendor/bin/lumen new lumen.levoo.com

/data/htdocs/lumen.levoo.com/blog/routes/web.php

你可以将所有路由都定义在routes/web.php中。最基本的 Lumen 路由接收:
http://laravelacademy.org/post/6337.html



$app->group(['prefix'=>'test'],function($app){
    $app->get("/index",["uses" => "TestController@index"]);
                                                                                                                                                                                                              
});


【lumen】基础点记录使用:blog.csdn.net/imdingding/article/details/48679359
app/Http/routes.php中进行路由配置可以使用如下路由组的形式,在路由上lumen和laravel有一些区别
$app->group(['prefix' => 'scrollnews','namespace' => 'App\Http\Controllers'],function($app) {
$app->get('/','NewsController@showall');
$app->get('/{time}_{newpage}.htm','NewsController@showtime');
$app->get('/{newpage}.htm', 'NewsController@show');

});


http://123.57.252.183/test/index
hello Lumen (5.4.5) (Laravel Components 5.4.*)
/data/htdocs/lumen.levoo.com/app/Http/Controllers/TestController.php

<?php

namespace App\Http\Controllers;

use App\user;   //新增部分
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class TestController extends BaseController
{
    //直接传人sql方式操作数据库
    function index(Request $request){
        echo "hello Lumen (5.4.5) (Laravel Components 5.4.*)。";die;                                                                                                                                          
        return User::all();
    }
}


以上实践来源及变通参看了:http://blog.5ibc.net/p/87952.html

PHP message: PHP Fatal error:  Uncaught UnexpectedValueException: The stream or file "/data/htdocs/lumen.levoo.com/storage/logs/lumen.log" could not be opened: failed to open stream: Permission denied in /data/htdocs/lumen.levoo.com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
mkdir
chmod -R 755 /data/htdocs/lumen.levoo.com/storage
chown -R www /data/htdocs/lumen.levoo.com/storage


Controller类的写法:https://segmentfault.com/q/1010000002727820
/data/htdocs/lumen.levoo.com/blog/app/Http/Controllers/AccountController.php



关于数据库配置文件:
默认情况下, Lumen 使用单一的 .env 文件来配置你的应用, 然而, 你也可以使用 Laravel 风格 的配置方法.
/data/htdocs/lumen.levoo.com/vendor/laravel/lumen-framework/config/database.php
文件夹下对应的配置文件复制到根目录下的 config 文件里面就行.
https://lumen.laravel-china.org/docs/5.3/configuration#configuration-files

Redis:
CACHE_DRIVER=file
SESSION_DRIVER=redis
QUEUE_DRIVER=sync

REDIS_HOST=192.168.1.248
REDIS_PASSWORD=null
REDIS_PORT=6379



今天在部署服务器的时候,使用composer来安装依赖。遇到了如下情况,这块出错好像和Redis配置有关,得在.env里配置好并运行起来。
  The Process class relies on proc_open, which is not available on your PHP installation.
  [ErrorException]                                          
  proc_get_status() has been disabled for security reasons
  开始的时候,我有些不知所措,于是冷静下来思考一番,然后goolge了一下
解决方法:
  在php.ini中,找到disable_functions选项,看看后面是否有proc_open函数被禁用了,如果有的话,去掉即可
  其实如果php的文档熟悉的话,你应该马上就能知道proc_open实际上是一个函数,是php用来和shell交互的函数,一般这种可以直接作用于操作系统的函数是非常不安全的,对于这种不安全的函数,总是要做一些措施来进行保护

php artisan make:migration create_table_cars --create=cars
php artisan make:migration create_table_cars --create=cars
Created Migration: 2017_03_04_160644_create_table_cars
/data/htdocs/lumen.levoo.com/database/migrations/2017_03_04_160644_create_table_cars.php

    public function up()
    {
        Schema::create('cars', function (Blueprint $table) {
            $table->increments('id');
            $table->string('make');                                                                                                                                  
            $table->string('model');
            $table->string('year');
            $table->timestamps();
        });
    }



php artisan migrate
Migrated: 2017_03_04_161708_create_table_cars

migrations记录历史 /car 两个表:
id int(10) UNSIGNED
make  varchar(255)
model varchar(255)
year varchar(255)
create d_attimestamp


问题实践来源:http://www.cnblogs.com/crisenchou/p/6237781.html
打开方法来自:http://www.codesec.net/view/497671.html?winzoom=1



Model这块和Controll层的配置:
1)Controll层, /data/htdocs/lumen.levoo.com/app/Http/Controllers/TestController.php

<?php

namespace App\Http\Controllers;
use App\Models\Information;
use App\Models\Collection;

//use App\User;     //新增部分APP目录下
use App\Models\User; //App\Models\User目录下
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class TestController extends BaseController
{
    //直接传人sql方式操作数据库
    function index(Request $request){
        /*
            $UserModel = new User();
            $result = $User::all(); //这样也成
            $result2 = $UserModel::all2(); //这样也成
        */
        $result = User::all();
        $result2 = User::all2();//这个在Model自定义的all2也能被调用输出结果

        print_r($result);
        echo "<hr>";                                                                                                                                                                                          
        print_r($result2);
    }
}


2)Model层:/data/htdocs/lumen.levoo.com/app/Models/User.php

<?php
//namespace App; //这个得注释掉,容易和App/User.php发生错误引用。
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
//默认操作数据库的users表,需要定制的话请看文档,下面有自己的配置。
class User extends Model
{
    /**
    * The connection name for the model.
    *
    * @var string
    */
    protected $connection = 'mysql';

    /**
    * 表名
    *
    * @var string
    */
    protected $table = 'levoo_sns_user'; //指定操作表名
    protected $primaryKey = "id";        //指定主键
    public $timestamps = false;
    protected $dateFormat = 'U';

    static public function all2(){
        $User = User::all();
        return $User;                                                                                                                                                                                          
    }
}


=================MVC模板学习=============================
/data/htdocs/lumen.levoo.com/app/Http/Controllers/TestController.php

<?php

namespace App\Http\Controllers;
use App\Models\Information;
use App\Models\Collection;

//use App\User;     //新增部分APP目录下
use App\Models\User; //App\Models\User目录下
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class TestController extends BaseController
{
    //直接传人sql方式操作数据库
    function index(Request $request){
        /*
            $UserModel = new User();
            $result = $User::all(); //这样也成
            $result2 = $UserModel::all2(); //这样也成
        */
        $result = User::all();
        //$result2 = User::all2();//这个在Model自定义的all2也能被调用输出结果
        /*
        print_r($result);                                                                                                                                            
        echo "<hr>";
        print_r($result2);
        */
        //view()->exists('user');
        return view('test', ['name' => 'jackX','results' => $result]);
    }
}


vi /data/htdocs/lumen.levoo.com/resources/views/test.blade.php


<!-- 该视图存放 resources/views/greeting.php -->

<html>
    <body>
        <h1>Hello, {{ $name }}</h1>
        <h1>Hello, {{ $name2 or 'Default' }}</h1>
        <h1>Hello, {!! $name !!}</h1>
        <h1>Array, {{ $results}}</h1>
        <h1>Array, {!! $results !!}</h1>
        Blade for each:<br>
        <h1>
            @foreach ($results as $user)
                <ul>
                <li>This is user {{ $user->id }}</li>
                <li>This is user {{ $user->mobile }}</li>
                <li>This is user {{ $user->fansmobile }}</li>
                <li>This is user {{ $user->followedTime }}</li>
                </ul>
            @endforeach
        </h1>
        <h1>
            @foreach ($results as $user)
                <ul>
                @if ($user->id == 1)
                   用户Id=1,标识一下:
                @endif
                <li>This is user {{ $user->id }}</li>
                <li>This is user {{ $user->mobile }}</li>
                <li>This is user {{ $user->fansmobile }}</li>
                <li>This is user {{ $user->followedTime }}</li>
                </ul>
            @endforeach
        </h1>
        <h1>只显示id=1的区块:</h1>
        <h1>
            @foreach ($results as $user)
                <ul>
                 @continue($user->id == 2)
                <li>This is user {{ $user->id }}</li>
                <li>This is user {{ $user->mobile }}</li>
                <li>This is user {{ $user->fansmobile }}</li>
                <li>This is user {{ $user->followedTime }}</li>
                </ul>
                 @break($user->id == 1)
            @endforeach
        </h1>
    </body>
</html>




模板输出:http://123.57.252.183/test/index
Hello, jackX

Hello, Default

Hello, jackX

Array, [{"id":1,"mobile":"1881**65108","fansmobile":"18810322234","followedTime":1211212121},{"id":2,"mobile":"1881**65108","fansmobile":"18810322232","followedTime":121212}]

Array, [{"id":1,"mobile":"1881**65108","fansmobile":"18810322234","followedTime":1211212121},{"id":2,"mobile":"1881**65108","fansmobile":"18810322232","followedTime":121212}]

Blade for each:
This is user 1
This is user 1881**65108
This is user 18810322234
This is user 1211212121
This is user 2
This is user 1881**65108
This is user 18810322232
This is user 121212
用户Id=1,标识一下:
This is user 1
This is user 1881**65108
This is user 18810322234
This is user 1211212121
This is user 2
This is user 1881**65108
This is user 18810322232
This is user 121212
只显示id=1的区块:

This is user 1
This is user 1881**65108
This is user 18810322234
This is user 1211212121

这个叫Blade的模板引擎解析成PHP的,也就是相当于没有啥大的损耗,如果它的算法还算先进的前提下,位置在:
/data/htdocs/lumen.levoo.com/storage/framework/views/9e3b647aebb6a248d1ae42408e87c3fc7f5bc520.php
为什么这么说呢,如下,我在想为何要搞成这样,PHP裸写不也一样么,像Ci框架啥的,思考思考,这样也算是能模板和程序分离罢:


        <h1>只显示id=1的区块:</h1>
        <h1>
            <?php $__currentLoopData = $results; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <ul>
                 <?php if($user->id == 2) continue; ?>
                <li>This is user <?php echo e($user->id); ?></li>
                <li>This is user <?php echo e($user->mobile); ?></li>
                <li>This is user <?php echo e($user->fansmobile); ?></li>
                <li>This is user <?php echo e($user->followedTime); ?></li>
                </ul>
                 <?php if($user->id == 1) break; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </h1>



主要是对这个模板有一个大体理解,和Smarty啥的有一个初步了解,参考自:
http://laravelacademy.org/post/6780.html




======================================================================
Nginx配置文件:

server
{
    listen       80 default_server;
    server_name  101.200.189.210 lumen.levoo.com;
    index index.html index.htm index.php;
    root  /data/htdocs/lumen.levoo.com/blog/public;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;


    location ~ .*\.(php|php5)?$
    {
        fastcgi_pass unix:/dev/shm/php-fcgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        #if (!-f $request_filename){                                                                                                  
        #    rewrite ^/(.+)$ /index.php?s=$1 last;
        #    break;
        #}
    }
    access_log /data/logs/nginx/access_lumen_levoo.log;
}



上面location / {里被注释掉的也成,只是优雅度不够,这块好像手册有说明,我当时把 try_files $uri $uri/ /index.php?$query_string;放到location ~ .*\.(php|php5)?$ 里了,发现不对。

http://123.57.252.183/foo
Hello World


老外:
http://stackoverflow.com/questions/32281294/lumen-simple-route-request-doesnt-work
老外也有这个问题:
http://laravel.io/forum/05-08-2014-nginx-laravel-routing-shows-404?page=1

主从数据库配置(多台读库配置):
http://blog.sina.com.cn/s/blog_9bbafb790102win1.html
基于Lumen搭建一个OAUTH2认证的API框架:
http://www.bibihub.com/php/lumen-mobile-api-oauth-2-authentication/

========DB学习=========
基本使用
注意:如果你想要使用DB门面,应该取消bootstrap/app.php文件中$app->withFacades()调用前的注释
vi bootstrap/app.php

下面这个需要门面:

$app->get('/foo', function () use ($app) {
    $results = app('db')->select("SELECT * FROM levoo_sns_user");
    print_r($results);
    $results = DB::select("SELECT * FROM levoo_sns_user");//这个需要门面
    print_r($results);
    return 'Hello World';                                          
});

图解证明:当地看北极星仰角,就是当地纬度;两者
图解证明:当地看北极星仰角,就是当地纬度;两者互为充分必要条件! 第一种情况:当地在北极点上

第二种情况:当地位于赤道上

http://wapwenku.baidu.com/view/fb2d8e52f46527d3240ce0ec.html?ssid=0&from=844b&uid=0&pu=sz@1320_2001#3
cd /usr/local/composer  ,sudo -u www -H composer.phar install ,会去读取:/usr/local/composer/composer.json文件。
chown -R www.www /data/htdocs/sd.levoo.com #否则会报:/data/htdocs/sd.levoo.com/vendor does not exist and could not be created.
sudo -u www -H composer.phar install

实践如下:


vi /etc/sudoers
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/mysql/bin:/usr/local/composer:/usr/local/php/bin


#sudo -u www -H composer.phar config -g repo.packagist composer https://packagist.phpcomposer.com                                                                                                    
  [ErrorException]                                                                                  
  touch(): Unable to create file /home/www/.composer/config.json because No such file or directory  

#mkdir  /home/www
#chown www.www /home/www
#chmod 755 /home/www
#sudo -u www -H composer.phar config -g repo.packagist composer https://packagist.phpcomposer.com


#sudo -u www -H composer.phar install
Composer could not find a composer.json file in /usr/local/composer
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section

建立composer.json如下,可以根据需要添加你所依赖的库,但下面一定得包含在内,autoload必须要指定app和test的目录不得省略。

{
  "require": {
    "tmtbe/swooledistributed":">2.0.0"
  },
"autoload": {
    "psr-4": {
      "app\\": "src/app",
      "test\\": "src/test"
    }
  }
}
/usr/local/composer/composer.json
运行:
#sudo -u www -H composer.phar install
Loading composer repositories with package information
Updating dependencies (including require-dev)
  [RuntimeException]                                                  
  /usr/local/composer/vendor does not exist and could not be created.

  [RuntimeException]                                                                
  /usr/local/composer/vendor/symfony/intl does not exist and could not be created

  - Installing symfony/intl (v3.3.8):
                                                                                          
  [Symfony\Component\Process\Exception\RuntimeException]                                  
  The Process class relies on proc_open, which is not available on your PHP installation.  
      
PHP需有proc_open,得从PHP的php.ini里给去掉:
; disable_functions = chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_
restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket

#sudo -u www -H composer.phar install
Composer could not find a composer.json file in /usr/local/php/etc
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
得cd到:/usr/local/composer 里,再执行:sudo -u www -H composer.phar install
#sudo -u www -H composer.phar install
  [ErrorException]                                          
  proc_get_status() has been disabled for security reasons   和上面一样:得从PHP的php.ini里给去掉。
  [RuntimeException]                                          
  Could not delete /usr/local/composer/vendor/symfony/intl:
  chown -R www.www  /usr/local/composer/vendor
  [ErrorException]                                                              
  file_put_contents(./composer.lock): failed to open stream: Permission denied   #写入/usr/local/composer/composer.lock权限不够。
[root@gitlab-jenkins_php-redis_123.57.252.183:/usr/local]
#chown www.www composer
#sudo -u www -H composer.phar install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。


From:https://getcomposer.org/download/
http://blog.csdn.net/yoywow/article/details/52074512

二、使用composer安装laravel/lumen:
遇到问题:
修改 composer 的全局配置文件(推荐方式)

打开命令行窗口(windows用户)或控制台(Linux、Mac 用户)并执行如下命令:
[root@a composer]# chtdocs
[root@a htdocs]# cd lumen.levoo.com/
[root@a lumen.levoo.com]# /usr/local/composer/composer.phar global require "laravel/lumen-installer"
Changed current directory to /root/.config/composer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
compser 执行命令提示do not run composer as root/super !
这个是因为composer为了防止非法脚本在root下执行,解决办法随便切换到非root用户即可
PATH变量设置Ok的方法如下:
打开~/.bashrc
sudo vim ~/.bashrc
添加行:
export PATH=$PATH:/home/lumen/.config/composer/vendor/bin


用Linux系统。比如要把/etc/apache/bin目录添加到PATH中,方法有三:
1.#PATH=c/etc/apache/bin
使用这种方法,只对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效

2.#vi /etc/profile
在适当位置添加 PATH=$PATH:/etc/apache/bin (注意:= 即等号两边不能有任何空格)
这种方法最好,除非你手动强制修改PATH的值,否则将不会被改变

3.#vi ~/.bash_profile
修改PATH行,把/etc/apache/bin添加进去
这种方法是针对用户起作用的
From:http://opsmysql.blog.51cto.com/2238445/665990


lumen没有成功:



useradd lumen
su lumen
cd /data/htdocs/laravel.levoo.com
/usr/local/composer/composer.phar  config -g repo.packagist composer https://packagist.phpcomposer.com


进行上述设置后,laravel有门,能下载了:
[lumen@a laravel.levoo.com]$ pwd
/data/htdocs/laravel.levoo.com
[lumen@a laravel.levoo.com]$ /usr/local/composer/composer.phar global require "laravel/lumen-installer"  
Changed current directory to /home/lumen/.config/composer
Using version ^1.0 for laravel/lumen-installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 10 installs, 0 updates, 0 removals
  - Installing symfony/process (v3.2.1) Downloading: 100%        
  - Installing psr/log (1.0.2) Downloading: 100%        
  - Installing symfony/debug (v3.2.1) Downloading: 100%        
  - Installing symfony/polyfill-mbstring (v1.3.0) Downloading: 100%        
  - Installing symfony/console (v3.2.1) Downloading: 100%        
  - Installing guzzlehttp/promises (v1.3.1) Downloading: 100%        
  - Installing psr/http-message (1.0.1) Downloading: 100%        
  - Installing guzzlehttp/psr7 (1.3.1) Downloading: 100%        
  - Installing guzzlehttp/guzzle (6.2.2) Downloading: 100%        
  - Installing laravel/lumen-installer (v1.0.2) Downloading: 100%        
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/filesystem ()
Writing lock file
Generating autoload files


生成文件如下:
[lumen@a composer]$ pwd
/home/lumen/.config/composer

[lumen@a composer]$ ls  /home/lumen/.config/composer
auth.json  composer.json  composer.lock  config.json  vendor


开始学习数据库:
http://blog.csdn.net/wowkk/article/details/52104689

/data/htdocs/lumen.levoo.com/blog/.env
APP_ENV=local
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=UTC

DB_CONNECTION=mysql
DB_HOST=10.44.202.177
DB_PORT=3306
DB_DATABASE=levoo_egg
DB_USERNAME=levoo
DB_PASSWORD=new@levoo.com

CACHE_DRIVER=memcached
QUEUE_DRIVER=sync

/data/htdocs/lumen.levoo.com/blog/app/Http/Controllers/AccountController.PHP


/data/htdocs/lumen.levoo.com/blog/routes/web.php
<?php

$app->group(["namespace"=>"App\Http\Controllers"], function()use($app){
    //账户控制器
    $app->get("/AccountController",["uses" => "AccountController@accountController"]);
});


model:/data/htdocs/lumen.levoo.com/blog/app/Models/User.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
class User extends Model
{
}



在app/Http/Controllers目录下AccountController.php,修改为

<?php

namespace App\Http\Controllers;

use App\user;   //新增部分
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class AccountController extends BaseController
{
    //直接传人sql方式操作数据库
    function accountController(Request $request){
        return User::all();
    }
}

http://101.200.189.210/AccountController/accountController
中老年人多多少少都会有些腰痛腿痛的毛病,这里和大家分享一个简单的神奇方法,5分钟缓解膝盖痛、腰痛、脚痛等。可以试试看!

粗盐、生姜、大葱一起炒热,具有消炎活血去风湿的功效,只需要5分钟就可以解除。

具体方法为,将粗盐用中火炒10分钟,倒在葱姜片上,待葱烂熟后,将葱姜捡出来,纯的热粗盐倒进布袋中,热敷膝盖、后腰等疼痛的关节,5分钟就管用。

如果粗盐凉了,可以加热后再用。如果觉得炒制麻烦,还可以用微波炉加热。
一、用户在网站上观看网络视频或者网络教程的时候,有时候用户需要把视频下载到本地计算机中,但是一般的下载网站又不会提供下载按钮给用户,这样用户如果不利用插件就很难完成这样特殊的需求。今天给大家介绍一款可以把任何网站中的视频下载到本机电脑中的Chrome插件:Video download helper。

二、Chrome Cache View软件来下载:
       Chrome Cache View,从名字上也可以看出来,这个软件的功能,比开发人员工具更加方便。免安装,运行后直接可以显示C:\Documents and Settings\用户名\Local Settings\Application Data\Google\Chrome\User Data\Default\Cache中的内容,不过是以原始地址显示的。直接复制出来地址就可下载了。


三、Chrome  的 Video Downloader professional插件,插件图标是向上箭头那个。
若是想要让牙齿洁白有光泽,建议刷牙时在牙膏里加入一滴柠檬汁,或是将柠檬皮磨碎,用牙刷沾一些来刷牙也有不错的效果。柠檬的用处非常多,以下的8种,您应该了解。

你喜欢柠檬吗?清爽的柠檬是许多人的最爱,除了用切片柠檬敷脸美白,近年来营养专家们纷纷关注柠檬所含有的丰富植化素,自制柠檬水饮用、或是利用柠檬皮的各种居家清洁妙招,天然无毒的生活形态已形成一股新风潮。阅读全文

当开启MySQL数据库主从时,会产生大量如mysql-bin.00000* log的文件,这会大量耗费您的硬盘空间。
mysql-bin.000001
mysql-bin.000002
mysql-bin.000003
mysql-bin.000004
mysql-bin.000005

有三种解决方法:1.关闭mysql主从,关闭binlog;2.开启mysql主从,设置expire_logs_days;3.手动清除binlog文件,> PURGE MASTER LOGS TO ‘MySQL-bin.010′;
实现:
1.关闭mysql主从,关闭binlog
# vim /etc/my.cnf  //注释掉log-bin,binlog_format # Replication Master Server (default) # binary logging is required for replication # log-bin=mysql-bin # binary logging format - mixed recommended # binlog_format=mixed
然后重启数据库
2.重启mysql,开启mysql主从,设置expire_logs_days
# vim /etc/my.cnf  //修改expire_logs_days,x是自动删除的天数,一般将x设置为短点,如10 expire_logs_days = x //二进制日志自动删除的天数。默认值为0,表示“没有自动删除”
此方法需要重启mysql,附录有关于expire_logs_days的英文说明
当然也可以不重启mysql,开启mysql主从,直接在mysql里设置expire_logs_days
> show binary logs; > show variables like '%log%'; > set global expire_logs_days = 10;
3.手动清除binlog文件
# /usr/local/mysql/bin/mysql -u root -p > PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 10 DAY); //删除10天前的MySQL binlog日志,附录2有关于PURGE MASTER LOGS手动删除用法及示例 > show master logs;
也可以重置master,删除所有binlog文件:
# /usr/local/mysql/bin/mysql -u root -p > reset master; //附录3有清除binlog时,对从mysql的影响说明
附录:
1.expire_logs_days英文说明
Where X is the number of days you’d like to keep them around. I would recommend 10, but this depends on how busy your MySQL server is and how fast these log files grow. Just make sure it is longer than the slowest slave takes to replicate the data from your master.
Just a side note: You know that you should do this anyway, but make sure you back up your mysql database. The binary log can be used to recover the database in certain situations; so having a backup ensures that if your database server does crash, you will be able to recover the data.
2.PURGE MASTER LOGS手动删除用法及示例,MASTER和BINARY是同义词
> PURGE {MASTER | BINARY} LOGS TO 'log_name' > PURGE {MASTER | BINARY} LOGS BEFORE 'date'
删除指定的日志或日期之前的日志索引中的所有二进制日志。这些日志也会从记录在日志索引文件中的清单中被删除MySQL BIN-LOG 日志,这样被给定的日志成为第一个。
实例:
> PURGE MASTER LOGS TO 'MySQL-bin.010'; //清除MySQL-bin.010日志 > PURGE MASTER LOGS BEFORE '2008-06-22 13:00:00'; //清除2008-06-22 13:00:00前binlog日志 > PURGE MASTER LOGS BEFORE DATE_SUB( NOW, INTERVAL 3 DAY); //清除3天前binlog日志BEFORE,变量的date自变量可以为'YYYY-MM-DD hh:mm:ss'格式。
3.清除binlog时,对从mysql的影响
如果您有一个活性的从属服务器,该服务器当前正在读取您正在试图删除的日志之一,则本语句不会起作用,而是会失败,并伴随一个错误。不过,如果从属服务器是休止的,并且您碰巧清理了其想要读取的日志之一,则从属服务器启动后不能复制。当从属服务器正在复制时,本语句可以安全运行。您不需要停止它们。

来自:http://m.toutiao.com/i6371662680515674625/?tt_from=copy_link&utm_campaign=client_share&app=news_article&utm_source=copy_link&iid=6966412074&utm_medium=toutiao_ios

背景: 有时间对Redis的一个测试来看,特别是经过了网络,此时,会傻傻分不清楚是Redis本来性能就差,还是网络不好(PHP调用Redis的机器和Redis分离或不在同一网段),这个工具可以直接在Redis上测试Redis,或是在PHP上测试Redis,这样有一个粗粒度的判断和把握。



阅读全文
分页: 9/248 第一页 上页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 下页 最后页 [ 显示模式: 摘要 | 列表 ]