编译php报错cc: 编译器内部错误:已杀死(程序 cc1) Please submit a full bug report, with preprocessed source if appropri

报错信息

7.0.23/ext/fileinfo/ -DPHP_ATOM_INC -I/usr/local/src/php-7.0.23/include -I/usr/local/src/php-7.0.23/main -I/usr/local/src/php-7.0.23 -I/usr/local/src/php-7.0.23/ext/date/lib -I/usr/include/libxml2 -I/usr/include/freetype2 -I/usr/local/src/php-7.0.23/ext/mbstring/oniguruma -I/usr/local/src/php-7.0.23/ext/mbstring/libmbfl -I/usr/local/src/php-7.0.23/ext/mbstring/libmbfl/mbfl -I/usr/local/src/php-7.0.23/ext/sqlite3/libsqlite -I/usr/local/src/php-7.0.23/ext/zip/lib -I/usr/local/src/php-7.0.23/TSRM -I/usr/local/src/php-7.0.23/Zend  -D_REENTRANT  -I/usr/include -g -O2 -fvisibility=hidden -pthread -DZTS   -c /usr/local/src/php-7.0.23/ext/fileinfo/libmagic/apprentice.c -o ext/fileinfo/libmagic/apprentice.lo
cc: 编译器内部错误:已杀死(程序 cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [ext/fileinfo/libmagic/apprentice.lo] 错误 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

解决方法:

这个原因是内存不足, 在linux下增加临时swap空间
step 1:
#sudo dd if=/dev/zero of=/home/swap bs=64M count=16
注释:of=/home/swap,放置swap的空间; count的大小就是增加的swap空间的大小,64M就是块大小,这里是64MB,所以总共空间就是bs*count=1024MB.这里分配空间的时候需要一点时间,等待执行完毕。

step 2:
# sudo mkswap /home/swap (可能会提示warning: don’t erase bootbits sectorson whole disk. Use -f to force,不用理会)
注释:把刚才空间格式化成swap各式
step 3:
#sudo swapon /home/swap
注释:使刚才创建的swap空间
step 4:执行你相关的操作,如make
如果创建了临时空间仍然提示 “g++: 内部错误:Killed (程序 cc1plus)”,可能分配的空间不够大,可继续分配更大的空间。

关闭:
step 1:sudo swapoff /home/swap
step 2:sudo rm /home/swap

ffmpeg-2.5.2 在centos 6.4 x86_64 上编译安装全过程

原始编译参数

./configure –extra-libs=-ldl –prefix=/opt/ffmpeg –enable-avresample –disable-debug –enable-nonfree –enable-gpl –enable-version3 –enable-libpulse –enable-libopencore-amrnb –enable-libopencore-amrwb –disable-decoder=amrnb –disable-decoder=amrwb –enable-libx264 –enable-libx265 –enable-libfdk-aac –enable-libvorbis –enable-libmp3lame –enable-libopus –enable-libvpx –enable-libspeex –enable-libass –enable-avisynth –enable-libsoxr –enable-libxvid –enable-libvo-aacenc

最终优化后编译参数

./configure –extra-libs=-ldl –prefix=/opt/ffmpeg –enable-avresample –disable-debug –enable-nonfree –enable-gpl –enable-version3 –enable-libpulse –enable-libopencore-amrnb –enable-libopencore-amrwb –disable-decoder=amrnb –disable-decoder=amrwb –enable-libx264 –enable-libfdk-aac –enable-libvorbis –enable-libmp3lame –enable-libopus –enable-libvpx –enable-libspeex –enable-libass –enable-avisynth –enable-libsoxr –enable-libxvid –enable-libvo-aacenc

为了不用编译每个包,添加如下yum源: 创建一个这样的文件: /etc/yum.repos.d/linuxtech.repo

[linuxtech]
name=LinuxTECH
baseurl=http://pkgrepo.linuxtech.net/el6/release/
enabled=1
gpgcheck=1
gpgkey=http://pkgrepo.linuxtech.net/el6/release/RPM-GPG-KEY-LinuxTECH.NET

  1. yasm/nasm not found or too old. Use –disable-yasm for a crippled build.
    sudo yum install yasm.x86_64 yasm-devel.x86_64
  2. ERROR: libass not found using pkg-config
    sudo yum install libass.x86_64 libass-devel.x86_64
  3. ERROR: libfdk_aac not found
    wget http://iweb.dl.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-0.1.3.tar.gz
    tar xzf fdk-aac-0.1.3.tar.gz
    cd fdk-aac-0.1.3
    ./configure
    make
    sudo make install
  4. ERROR: libmp3lame >= 3.98.3 not found
    sudo yum install libmp3lame.x86_64 libmp3lame-devel.x86_64
  5. ERROR: libopencore_amrnb not found
    sudo yum install libopencore-amr-devel.x86_64 libopencore-amr.x86_64
  6. ERROR: libopencore_amrwb not found
    sudo yum install libopencore-amr-devel.x86_64 libopencore-amr.x86_64
  7. ERROR: opus not found using pkg-config sudo yum install opus.x86_64 opus-devel.x86_64
  8. ERROR: libpulse not found using pkg-config
    sudo yum install pulseaudio-libs.x86_64 pulseaudio-libs-devel.x86_64
  9. ERROR: libsoxr not found
    sudo yum install libsoxr-devel.x86_64 libsoxr.x86_64
  10. ERROR: speex not found using pkg-config
    sudo yum install speex.x86_64 speex-devel.x86_64
  11. ERROR: libvo_aacenc not found
    wget http://hivelocity.dl.sourceforge.net/project/opencore-amr/vo-aacenc/vo-aacenc-0.1.3.tar.gz
    tar xzf vo-aacenc-0.1.3.tar.gz
    cd vo-aacenc-0.1.3
    ./configure
    make
    sudo make install
  12. ERROR: libvorbis not found
    sudo yum install libvorbis-devel.x86_64 libvorbis.x86_64
  13. ERROR: libvpx decoder version must be >=0.9.1
    sudo yum install libvpx.x86_64 libvpx-devel.x86_64
  14. ERROR: libx264 not found
    git clone git://git.videolan.org/x264.git
    cd x264
    ./configure –enable-static
    make
    sudo  make install
    sudo ldconfig
  15. ERROR: x265 not found using pkg-config
    去掉编译参数: –enable-libx265
    ./configure –extra-libs=-ldl –prefix=/opt/ffmpeg –enable-avresample –disable-debug –enable-nonfree –enable-gpl –enable-version3 –enable-libpulse –enable-libopencore-amrnb –enable-libopencore-amrwb –disable-decoder=amrnb –disable-decoder=amrwb –enable-libx264 –enable-libfdk-aac –enable-libvorbis –enable-libmp3lame –enable-libopus –enable-libvpx –enable-libspeex –enable-libass –enable-avisynth –enable-libsoxr –enable-libxvid –enable-libvo-aacenc
  16. ERROR: libxvid not found
    sudo yum install libxvidcore-devel.x86_64 libxvidcore.x86_64
  17. ./ffmpeg: error while loading shared libraries: libvo-aacenc.so.0: cannot open shared object file: No such file or directory

    sudo vim /etc/ld.so.conf.d/local_lib.conf

    /usr/local/lib

    sudo ldconfig

[转]ffmpeg+ffserver搭建流媒体服务器

使用FFMpeg和FFServer来搭建流媒体服务器(在windows下实现)
一、基础知识
需要用到以下四个东西:
1. ffmpeg.exe
   负责媒体文件的transcode工作,把你服务器上的源媒体文件转换成要发送出去的流媒体文件。
2. ffserver.exe
   负责响应客户端的流媒体请求,把流媒体数据发送给客户端。
3. ffserver.conf
   ffserver启动时的配置文件,在这个文件中主要是对网络协议,缓存文件feed1.ffm(见下述)和要发送的流媒体文件的格式参数做具体的设定。ffserver.conf参数说明可以访问FFMPEG的官方文档查看。http://ffmpeg.org/ffserver.html
4. feed1.ffm
   可以看成是一个流媒体数据的缓存文件,ffmpeg把转码好的数据发送给ffserver,如果没有客户端连接请求,ffserver把数据缓存到该文件中。
可以在ffserver.conf文件中设置feed1.ffm文件的大小,当缓存数据超过这个大小,它会自动覆盖原始数据。
二、如何实现
1.配置ffserver.conf文件
 下面是一个示例:
HTTPPort 8090                       #绑定端口号
BindAddress 0.0.0.0             #绑定ip
MaxHTTPConnections 2000         #最大HTTP连接数
MaxClients 1000                 #最大客户端连接数
MaxBandwidth 1000               #最大带宽
CustomLog –                     #日志文件,“-”为直接打印
NoDaemon                        #默认全局参数
<Feed feed1.ffm>                #Feed:每一个输入建立一个Feed
    File tests/feed1.ffm             #Feed缓存文件
    FileMaxSize 10M               #缓存文件最大值
    ACL allow 127.0.0.1             #允许写入Feed的ip
</Feed>
#传递实时流
<Stream stream1.flv>               #Stream:每一个广播(转换后的视频流)的转码设置项目
    Format flv                      #视频流格式
    Feed feed1.ffm                  #视频流的种子来源
    VideoFrameRate 35              #视频帧频
    VideoBitRate 128                #视频比特率
    VideoSize 160×80                #视频帧大小
    AVOptionVideo flags +global_header
    AudioBitRate 24                 #音频比特率
    AudioChannels 1                 #音频声道
    AudioSampleRate 44100
    AVOptionAudio flags +global_header
</Stream>
#传递本地文件
<Stream stream2>
File “files/test.avi”
Format avi
</Stream>
<Stream stat.html>  #检查服务器状态,ffserver启动后,在web浏览器中输入地址:http://localhost:8090/stat.html,若能看到 ffserver Status 说明成功启动,通过内容可以看到在ffserver.conf配置的流信息等内容
Format status
</Stream>
2.启动流媒体服务器
a. 可以在ffmpeg.exe、ffserver.exe所在的路径下创建一个.bat文件,在里面写入:ffserver -f ffserver.conf
b. 也可以打开cmd.exe  cd到你的ffmpeg.exe、ffserver.exe所在的路径,输入:ffserver -f ffserver.conf
       执行完这一步,你就可以在web浏览器中输入地址:http://localhost:8090/stat.html,若能看到 ffserver Status 说明成功启动,通过内容可以看到在ffserver.conf配置的流信息等内容。
注意:如果传输的是本地文件,那么到这一步就可以打开客户端(vlc)请求视频流地址:打开vlc–>File–>OpenNetwork–>URL中填写“http://ip:8090/stream2”–>Open (ip为FFserver所在主机电脑的ip,如果是本机测试可以使用localhost;stream2为FFserver配置文件中Stream项的名字,本例中即为stream2)。
3.FFMpeg产生实时流(如果传输的是本地文件,则不需要执行该步骤)
a. 可以在ffmpeg.exe、ffserver.exe所在的路径下创建一个.bat文件,在里面写入:ffmpeg -i rtsp://192.168.1.111:8000 http://localhost:8090/feed1.ffm
b. 也可以打开cmd.exe  cd到你的ffmpeg.exe、ffserver.exe所在的路径,输入:ffmpeg -i rtsp://192.168.1.111:8000 http://localhost:8090/feed1.ffm
其中:
#-i:为输入参数选项
#rtsp://192.168……:为输入的RTSP视频流来源
#http://localho……:为FFserver配置文件中设置的Feed的监听地址和端口
4.实现播放
打开客户端(vlc)请求视频流地址:打开vlc–>File–>OpenNetwork–>URL中填写“http://ip:8090/stream1”–>Open (ip为FFserver所在主机电脑的ip,如果是本机测试可以使用localhost;stream2为FFserver配置文件中Stream项的名字,本例中即为stream1)。
三、总结
ffserver先于ffmpeg启动,它在启动的时候需要加参数-f指定其配置文件。ffserver启动后,feed1.ffm就会被创建,这时如果你打开feed1.ffm看看,会发现feed1.ffm开始的部分已经写入了内容,你可以找到关键字ffm以及向客户端传送流的配置信息,在feed1.ffm做缓冲用的时候,这些信息是不会被覆盖掉的,可以将它们理解为feed1.ffm文件头。
ffserver启动后,ffmpeg启动,它启动时加的一个关键参数就是“http://ip:8090/feed1.ffm”,其中ip是运行ffserver主机的ip,如果ffmpeg和ffserver都在同一系统中运行的话,用localhost也行。ffmpeg启动后会与ffserver建立一个连接(短暂的连接),通过这第一次的连接,ffmpeg从ffserver那里获取了向客户端输出流的配置,并把这些配置作为自己编码输出的配置,然后ffmpeg断开了这次连接,再次与ffserver建立连接(长久的连接),利用这个连接ffmpeg会把编码后的数据发送给ffserver。
如果你观察ffserver端的输出就会发现这段时间会出现两次HTTP的200,这就是两次连接的过程。
ffmpeg获取数据后,按照输出流的编码方式编码,然后发送给ffserver,ffserver收到ffmpeg的数据后,如果网络上没有播放的请求,就把数据写入feed1.ffm中缓存,写入时把数据加上些头信息然后分块,每块4096B(每块也有结构),当feed1.ffm的大小到了ffserver.conf中规定的大小后,就会从文件开始(跳过头)写入,覆盖旧的数据。直到网络上有播放的请求,ffserver从feed1.ffm中读取数据,发送给客户端。
                                 2.http://blog.csdn.net/vblittleboy/article/details/8549835
                         3.http://ffmpeg.org/ffserver.html
友情链接:FFMPEG和FFSERVER搭建流媒体服务器实例,可以根据自己的需求修改里面的ffserver.conf文件。

[转]阿里巴巴开源项目TAC——新的服务端开发模式尝试

尝试

TAC是一个基于java的微服务容器,提供从业务代码编写、编译、发布、jar动态加载、运行等一系列常用开发流程的支持,是天猫App在服务端开发模式下的新尝试。TAC和客户端框架Tangram结合,极大提高开发效率;TAC目前在天猫App、手机淘宝特价版广泛使用;

疼痛之初——产生背景

天猫App(以下简称猫客)首页从2015年的坑位运营走向2016年的全面个性化,当时猫客首页的个性化业务多大50多处。以首页为例,这个过程中除了接入导购链路的二方服务之外,接入了大量的三方服务;同时我们发现:

  • 首页应用越来越复杂、庞大,应用代码修改、编译部署耗费时间太长,大部分时间都是苦力劳动;
  • 线上定位问题周期太长,从问题发现到定位再到处理,需要经过客户端、服务端、下游各种服务提供方,链路太长影响业务快速支撑;
  • 大量服务的接入导致发布线上部署频繁,一个简单服务的接入,几行代码的修改导致首页应用重新开发编译部署,影响整个首页稳定性;

当时微服务的概念已经很火,同时阿里内部也开始大力推广docker(现在大部分应用都跑在docker上)。我们想过将庞大的首页应用拆分成微服务,但是和基础服务不同,前台业务变化快,修改频繁,拆分之后开发同学依然要面临各种服务接入等体力劳动,同时需要维护拆分之后的多个应用,反而增加了劳动成本,因此拆分成微服务的方式治标不治本;


解决之道——TAC

在此背景下TAC孕育而生,它提供低成本开发与发布流程、低成本搭建与维护开发环境、高稳定性保障;TAC通过热部署的方式使得研发同学够从苦力劳动中解放出来,回归到业务开发中去,同时一个基础服务接入之后,能够提供给多个业务使用;在此模式下,业务能够进行更细粒度的拆分,且故障隔离业务A的改动不会影响业务B;

在TAC的帮助下,频繁修改的新业务可快速上线,不会出现因为修改一个字段、几行代码就需要重新发布整个应用的情况;同时与tangram结合,实现页面卡片、坑位的快速调整;


经过近三年的沉淀,我们今日放出了开源版本,将集团版本的TAC剥离与阿里相关的中间件、网络、协议、部署环境等,保留其核心功能;开源版本提供了编译、热加载、运行的基础能力;

TAC开源版本

系统结构


  • 开源版本分两部分,tac容器和tac控制台,存储和通信都依赖redis。
  • 为了简便,容器与外部服务直接的交互只通过http进行;
  • 同时为了提升开发体验,提供了与gitlab集成的能力,用户可直接gitlab提交代码并在控制台操作发布;快速验证;

核心类加载器


上图是tac的类加载器结构,每个线上的微服务实例都通过一个新的classloader加载,同时为了方便用户扩展新的数据源,在AppClassLoader上扩展了一个classloader以加载第三方数据源(当然也可以直接在代码中扩展,见tac-infrastructure);

Quick Start —— 如何使用

  • 安装 redis
  • 运行 container
java -jar tac-container.jar
  • 运行 console 控制台
java -jar tac-console.jar --admin
  • 成功后可打开控制台
http://localhost:7001/#/tacMs/list
  • 代码开发
    • 添加 SDK 依赖
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>tac-sdk</artifactId>
    <version>${project.version}</version>
</dependency>
  • 编写代码
public class HelloWorldTac implements TacHandler<Object> {

    /**
     * 引入日志服务
     */
    private TacLogger tacLogger = TacServiceFactory.getLogger();

    /**
     * 编写一个实现TacHandler接口的类
     *
     * @param context
     * @return
     * @throws Exception
     */

    @Override
    public TacResult<Object> execute(Context context) throws Exception {

        // 执行逻辑
        tacLogger.info("Hello World");

        Map<String, Object> data = new HashMap<>();
        data.put("name", "hellotac");
        data.put("platform", "iPhone");
        data.put("clientVersion", "7.0.2");
        data.put("userName", "tac-userName");
        return TacResult.newResult(data);
    }
}
  • 本地编译、打包
  • 发布及测试

  • 正式发布
  • 线上验证
curl  http://localhost:8001/api/tac/execute/helloworld -s|json
{
  "success": true,
  "msgCode": null,
  "msgInfo": null,
  "data": {
    "helloworld": {
      "data": {
        "name": "hellotac",
        "clientVersion": "7.0.2",
        "userName": "tac-userName",
        "platform": "iPhone"
      },
      "success": true,
      "msCode": "helloworld"
    }
  },
  "hasMore": null,
  "ip": "127.0.0.1"
}

Git 私有服务器搭建

有时候需要自己搭建一台Git服务器作为私有仓库使用。

接下来我们将以 Centos 为例搭建 Git 服务器。

1、安装Git

$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
$ yum install git

接下来我们 创建一个git用户组和用户,用来运行git服务:

$ groupadd git
$ useradd git -g git

2、创建证书登录

收集所有需要登录的用户的公钥,公钥位于id_rsa.pub文件中,把我们的公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。

如果没有则需要自己产生一个 ssh-keygen 在.ssh/id_rsa.pub 产生公钥

如果没有该文件创建它:

$ cd /home/git/
$ mkdir .ssh
$ chmod 755 .ssh
$ touch .ssh/authorized_keys
$ chmod 644 .ssh/authorized_keys

3、初始化Git仓库

首先我们选定一个目录作为Git仓库,假定是/home/gitrepo/runoob.git,在/home/gitrepo目录下输入命令:

$ cd /home
$ mkdir gitrepo
$ chown git:git gitrepo/
$ cd gitrepo

$ git init --bare runoob.git
Initialized empty Git repository in /home/gitrepo/runoob.git/

以上命令Git创建一个空仓库,服务器上的Git仓库通常都以.git结尾。然后,把仓库所属用户改为git:

$ chown -R git:git runoob.git

4、克隆仓库

$ git clone git@192.168.45.4:/home/gitrepo/runoob.git
Cloning into 'runoob'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

192.168.45.4 为 Git 所在服务器 ip ,你需要将其修改为你自己的 Git 服务 ip。

这样我们的 Git 服务器安装就完成。

本地操作:

 

1,git clone git@192.168.45.4:/home/gitrepo/runoob.git 
2,git init
3, git remote add origin git@192.68.45.3:/home/gitrepo/runoob.git
4, 创建文件touch README.MD
5,git add README.MD
6,git commit -m "add first file"
5,git push -u origin master
(仅第一次推分支需要-u)

Advanced Usage: Admin Server

link:https://docs.hhvm.com/hhvm/advanced-usage/admin-server

The admin server allows the administrator of the HHVM server to query and control the HHVM server process. It is different and separate than the primary HHVM server that you specified with -m server or -m daemon.

To turn on the admin server, you specify the following options at the command line via -d or within your server.ini (or equivalent).

hhvm.admin_server.port=9001
hhvm.admin_server.password=SomePassword

The port can be any open port. And you should always specify a password to secure the admin port since you don’t want just anybody being able to control your server. In fact, you will probably want to put the admin server behind a firewall. You will specify the password with every request to the admin port.

The admin server uses the same protocol as the main server – so, if you’re using FastCGI mode, the admin server will also be FastCGI, and you will need to configure a front-end webserver (like nginx). If you are using Proxygen mode, the admin server will be an HTTP server.

Querying the Admin Server

Once you have set up your admin server, you can query it via curl.

curl http://localhost:9001/

will bring up a list of commands you can use to control and query your admin server.

The port associated with the curl command is the hhvm.admin_server port set above if you are using ProxygenIf you are using FastCGI, then the port will be the webserver port that is the front end to FastCGI.

Sending a Command

Use one of the commands listed with the curl sequence above, along with your password, to send a command to the admin server.

curl http://localhost:9001/compiler-id?auth=SomePassword

Further Reference

There is a good blog post discussing the admin server even further.

[转]Linux系统安装w3af

  w3af这个工具是扫描网站漏洞,比如 SQL注入、盲注、本地\远程文件包含、跨站脚本攻击、跨站伪造请求等。

找了一些正规的工具定义介绍:w3af是一个Web应用安全的攻击、审计(分析)平台,通过增加插件来对功能进行扩展,这是一款用python写的工具,支持GUI,也支持命令行模式。

w3af目前已经集成了非常多的安全审计及攻击插件,并进行了分类,用户在使用的时候,可

以直接选择已经分类好的插件,只需要填写上URL地址即可对目标站点进行安全审计,并且集成了一些好用的小工具,如自定义request功能、Fuzzy

request功能、代理功能、加解密功能,支持非常多的加解密算法,用户完全可以使用w3af完成对一个网址的安全审计(分析)工作。

《w3af用户手册》英文版本于2012年8月8日发布,由Andres Riancho编写,Javier Andalia、Mike Harbison、Andy Bach、Chris Teodorski审阅。中文版本于2013年4月3日发布,由IDF实验室研究员lenchio翻译,研究员做个好人校对、修改、制作,实习生Leo亦参与了文档校对工作。

可以通过连接下载.有windows、Linux版本.

https://sourceforge.net/projects/w3af/files/w3af/

还有另外一种方法……

sudo apt-get install w3af         即可

本次教程讲的是Ubuntu下git从GitHub安装….

https://github.com/andresriancho/w3af

命令如下:还是觉得图形界面直观….

git clone –depth 1 https://github.com/andresriancho/w3af.git

cd w3af

./w3af_gui

到这一步后,会提示你安装某些工具,安装好后,就可以启动了。祝你好运!!!

作者:不着调的小男生
链接:https://www.jianshu.com/p/a4584e7d0d25
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

[Re:]A Stick Figure Guide to the Advanced Encryption Standard (AES)

(A play in 4 acts. Please feel free to exit along with the stage character that best represents you. Take intermissions as you see fit. Click on the stage if you have a hard time seeing it. If you get bored, you can jump to the code. Most importantly, enjoy the show!)

Act 1: Once Upon a Time…

intro
sad
aes act 1 scene 03 cinderella
aes act 1 scene 04 started
aes act 1 scene 05 judge
aes act 1 scene 06 nbs decree
aes act 1 scene 07 lucifer
aes act 1 scene 08 anoint des
aes act 1 scene 09 des ruled
aes act 1 scene 10 des defeated
aes act 1 scene 11 triple des
aes act 1 scene 12 nist decree
aes act 1 scene 13 rallied
aes act 1 scene 14 rijndael
aes act 1 scene 15 vote
aes act 1 scene 16 won
aes act 1 scene 17 intel
aes act 1 scene 18 crypto question

Act 2: Crypto Basics

aes act 2 scene 01 three big ideas
aes act 2 scene 02 confusion
aes act 2 scene 03 diffusion
aes act 2 scene 04 key secrecy
aes act 2 scene 05 aes details question

Act 3: Details

aes act 3 scene 01 sign this
aes act 3 scene 02 agreement
aes act 3 scene 03 state matrix
aes act 3 scene 04 initial round
aes act 3 scene 05 xor tribute
aes act 3 scene 06 key expansion part 1
aes act 3 scene 07 key expansion part 2a
aes act 3 scene 08 key expansion part 2b
aes act 3 scene 09 key expansion part 3
aes act 3 scene 10 intermediate round start
aes act 3 scene 11 substitute bytes
aes act 3 scene 12 shift rows
aes act 3 scene 13 mix columns
aes act 3 scene 14 add round key
aes act 3 scene 15 final round
aes act 3 scene 16 more rounds the merrier
aes act 3 scene 17 tradeoffs
aes act 3 scene 18 security margin
aes act 3 scene 19 in pictures
aes act 3 scene 20 decrypting
aes act 3 scene 21 modes
aes act 3 scene 22 questions what really happens
aes act 3 scene 23 math

Act 4: Math!

aes act 4 scene 01 algebra class
aes act 4 scene 02 reviewing the basics
aes act 4 scene 03 algebra coefficients
aes act 4 scene 04 remember multiplication growth
aes act 4 scene 05 cant go bigger
aes act 4 scene 06 clock math
aes act 4 scene 07 clock math polynomials
aes act 4 scene 08 divide by mx
aes act 4 scene 09 logarithms
aes act 4 scene 10 using logarithms
aes act 4 scene 11 polynomial as byte
aes act 4 scene 12 byte operations
aes act 4 scene 13 byte inverses
aes act 4 scene 14 sbox math
aes act 4 scene 15 round constants
aes act 4 scene 16 mix columns math
aes act 4 scene 17 crib sheet
aes act 4 scene 18 got it now
aes act 4 scene 19 so much more
aes act 4 scene 20 gotta go
aes act 4 scene 21 the end

Epilogue

I created a heavily-commented AES/Rijndael implementation to go along with this post and put it on GitHub. In keeping with the Foot-Shooting Prevention Agreement, it shouldn’t be used for production code, but it should be helpful in seeing exactly where all the numbers came from in this play. Several resources were useful in creating this:

Please leave a comment if you notice something that can be better explained.

Update #1: Several scenes were updated to fix some errors mentioned in the comments.
Update #2: By request, I’ve created a slide show presentation of this play in both PowerPoint and PDFformats. I’ve licensed them under the Creative Commons Attribution License so that you can use them as you see fit. If you’re teaching a class, consider giving extra credit to any student giving a worthy interpretive dance rendition in accordance with the Foot-Shooting Prevention Agreement.

wordpress挂站–Error establishing a database connection

今天莫名其妙我的博客出现Error establishing a database connection,一看应该是数据连接不上了。首先看了下wp-config.php,发现无异常。重启nginx,更换php5均没有效果。网上查了下,说是http://blog.csdn.net/mwb310/article/details/53009920,众说纷纭,有文件格式错误,mysql版本错误等等,试了均无效。

想着不如先把sql dump一份备份,所以

mysqldump -uxxx -pxxx --dataname >wordpress.log

发现:

 

warning : 250 clients are using or haven’t closed the table properly
status : OK
wangchunwei.wp_statistics_search
warning : 156 clients are using or haven’t closed the table properly
status : OK
wangchunwei.wp_statistics_useronline
warning : 252 clients are using or haven’t closed the table properly
status : OK
wangchunwei.wp_statistics_visit
warning : 252 clients are using or haven’t closed the table properly
status : OK
wangchunwei.wp_statistics_visitor
warning : 252 clients are using or haven’t closed the table properly
status : OK
wangchunwei.wp_term_relationships
warning : 32 clients are using or haven’t closed the table properly
status : OK
wangchunwei.wp_term_taxonomy
warning : 31 clients are using or haven’t closed the table properly
status : OK

 

 

mysqldump: Got error: 145: Table ‘./xxx/wp_options’ is marked as crashed and should be repaired when using LOCK TABLES

网上参考了:

修复 MySQL 数据库数据表问题可以由 mysqlcheck 来解决,先用 mysqlcheck 查看一下:

# mysqlcheck -u root -p wordpress
Enter password:

然后添加 –auto-repair 参数自动修复,最好修复前备份一下数据库:

# mysqldump -u root -p wordpress > wordpress.sql
Enter password:

# mysqlcheck -u root -p wordpress --auto-repair
Enter password:
wordpress.wp_commentmeta
error    : Table upgrade required. Please do "REPAIR TABLE `wp_commentmeta`" or dump/reload to fix it!
wordpress.wp_comments
error    : Table upgrade required. Please do "REPAIR TABLE `wp_comments`" or dump/reload to fix it!
wordpress.wp_links
error    : Table upgrade required. Please do "REPAIR TABLE `wp_links`" or dump/reload to fix it!
wordpress.wp_options
error    : Table upgrade required. Please do "REPAIR TABLE `wp_options`" or dump/reload to fix it!
wordpress.wp_postmeta
error    : Table upgrade required. Please do "REPAIR TABLE `wp_postmeta`" or dump/reload to fix it!
wordpress.wp_posts
error    : Table upgrade required. Please do "REPAIR TABLE `wp_posts`" or dump/reload to fix it!
wordpress.wp_term_relationships                OK
wordpress.wp_term_taxonomy
error    : Table upgrade required. Please do "REPAIR TABLE `wp_term_taxonomy`" or dump/reload to fix it!
wordpress.wp_terms
error    : Table upgrade required. Please do "REPAIR TABLE `wp_terms`" or dump/reload to fix it!
wordpress.wp_usermeta
error    : Table upgrade required. Please do "REPAIR TABLE `wp_usermeta`" or dump/reload to fix it!
wordpress.wp_users
error    : Table upgrade required. Please do "REPAIR TABLE `wp_users`" or dump/reload to fix it!

Repairing tables
wordpress.wp_commentmeta                       OK
wordpress.wp_comments                          OK
wordpress.wp_links                             OK
wordpress.wp_options                           OK
wordpress.wp_postmeta                          OK
wordpress.wp_posts                             OK
wordpress.wp_term_taxonomy                     OK
wordpress.wp_terms                             OK
wordpress.wp_usermeta                          OK
wordpress.wp_users                             OK

网站恢复了!应该是链接没有释放

[转]Lumen和Laravel错误处理机制修改

在使用Laravel或者Lumen时会碰到这种情况,如果php的代码中产生了Notice或者Warning,会导致Lumen跳到错误页,日志中会打印一个很长很长的stack trace,如下图:

$app->get('/test', function () use ($app) {
	$arr = [];
	print($arr['name']);
});
#请求/test 产生的日志
[2017-07-12 11:55:54] lumen.ERROR: ErrorException: Undefined index: name in /home/vagrant/Code/featurestream/routes/web.php:16
Stack trace:
#0 /home/vagrant/Code/featurestream/routes/web.php(16): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(8, 'Undefined index...', '/home/vagrant/C...', 16, Array)
#1 [internal function]: Closure->{closure}()
#2 /home/vagrant/Code/featurestream/vendor/illuminate/container/BoundMethod.php(29): call_user_func_array(Object(Closure), Array)
....

上面的日志只截取了一小部分,实际运行时最简单的api请求Lumen的stack trace会有30层左右,Laravel的会有60层..
另外一个重要的问题是,这种处理机制会让一些小错误把整个请求搞挂,代码中到处加if(isset($arr['xx'])) 或者设置默认值。
对于这个问题,Laravel和Lumen设计的初衷是好的:所有的PHP错误都应该被处理,包括Notice和Warning。就是太严格了,有时候我们并不需要代码有这么严格的检查,出现Notice或者Warning时,只需要打印个模块日志或者有PHP日志就行。
先看下Lumen中的错误是如何处理的(Laravel中也差不多,不再单独讲)。

错误处理流程

错误Handler

先看Lumen的入口:bootstrap/app.php,有一段错误处理相关的代码:

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

singleton是往app(Lumen的服务容器)里注入实例的方法,这里实例化了一个ExceptionHandler类,实例为Handler。后面的代码如果有从$app里取ExceptionHandler的实例的话,会返回Handler这个类的实例。
Handler类在App\Exceptions目录下,代码如下。比较简单,只包含两个方法,再去看父类(Laravel\Lumen\Exceptions\Handler)的方法逻辑会发现,report方法负责打印日志(也就是上文那个长长的trace),render方法会根据错误类型的不同构建错误页面

public function report(Exception $e)
{
    parent::report($e);
}

public function render($request, Exception $e)
{
    return parent::render($request, $e);
}

错误的处理逻辑找到了,如何触发进入这个逻辑的呢?

错误触发

正常情况下,PHP产生Notice或者Warning是不会抛出Exception的,会产生Exception肯定是框架内部做了更改。
bootstrap/app.php中没找到设置错误处理的地方,接着往下看Lumen框架的容器类Application(Lumen的核心类和入口),目录:vendor/laravel/lumen-framework/src/Application.php
可以看到在其构造函数中调用了一个registerErrorHandling方法,方法代码:

/**
 * Set the error handling for the application.
 *
 * @return void
 */
protected function registerErrorHandling()
{
    error_reporting(-1);

    set_error_handler(function ($level, $message, $file = '', $line = 0) {
        if (error_reporting() & $level) {
            throw new ErrorException($message, 0, $level, $file, $line);
        }
    });

    set_exception_handler(function ($e) {
        $this->handleUncaughtException($e);
    });

    register_shutdown_function(function () {
        $this->handleShutdown();
    });
}

set_error_handler是PHP设置错误处理的方法。registerErrorHandling下用error_reporting(-1)把PHP的报错开关都打开,这样所有级别的错误都会触发error_handler。在error_handler中抛出了一个ErrorException异常。
至此,我们知道ErrorException这个异常是怎么产生的了,知道异常会交由谁来处理了(上一节中的Handler类)。不过还有个疑问,ErrorException和Handler是怎么关联起来的?

ErrorException和Handler

set_error_handler设置的方法中会抛出异常,那肯定存在针对异常的try catch块。
从请求路口public/index.php往下看,
–>bootstrap/app.php –>Application.php -> run –>Application.php -> dispatch
在dispatch方法中发现了try catch的逻辑,在catch到Exception后调用了Handler的report和render方法。

public function dispatch($request = null)
{
   list($method, $pathInfo) = $this->parseIncomingRequest($request);
   try {
			...
   } catch (Exception $e) {
       return $this->prepareResponse($this->sendExceptionToHandler($e));
   } catch (Throwable $e) {
       return $this->prepareResponse($this->sendExceptionToHandler($e));
   }
}
protected function sendExceptionToHandler($e)
{
   $handler = $this->resolveExceptionHandler();

   if ($e instanceof Error) {
       $e = new FatalThrowableError($e);
   }

   $handler->report($e);

   return $handler->render($this->make('request'), $e);
}

解决

知道了错误从触发到结束的整个流程,再来看怎么解决.

方法1.屏蔽错误

简单粗暴的方法,既然框架用来error_reporting(-1)打开了所有错误开关,那我们再用error_reporting把我们不关心的错误给屏蔽了。把下面代码加在bootstrap/app.php中,注意得加在Applition实例化之后

error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);

这种方法的弊端显而易见,我们只是不想让E_NOTICE搞挂请求,但是这类错误还是得关注和修复的。。

方法2.修改Handler

既然是Handler负责错误处理,那我们修改Handler(App\Exceptions\Handler)的逻辑就行。

public function report(Exception $e)
{
    //parent::report($e);
    Log::warning($e->getMessage(), ['file' => $e->getFile(), 'line' => $e->getLine()]);
}

public function render($request, Exception $e)
{
    //return parent::render($request, $e);
    header('Content-type: application/json');
    echo json_encode(['errmsg' => $e->getMessage()]);
    return ;
}

如上代码,将错误处理逻辑进行更改,只打印简单的日志,并且也不跳到错误页了。
不过,这种方法还是有问题:

  1. 代码产生的NOTICE和WARNING还是会中断执行流程(因为会抛出异常)。比如一个请求中执行A->B->C三个方法,如果B中产生了一个NOTICE,整个请求还是会被中断,C不会被执行。
  2. 如果一个请求原本不是返回json,是返回一个view,则上面的render方法就不适用了。

方法3.在业务逻辑顶层中catch异常

原理类似方法2,只不过把异常的处理从Handler中移到了业务逻辑里(比如Controller中)。
这个方法的问题和方法2一样,NOTICE还是会中断请求…

方法4.修改error_handler,不抛出异常

罪魁祸首就在于那个set_error_handler注册的处理方法遇到PHP错误就会抛出异常,那我们修改他就行。
set_error_handler所在的registerErrorHandling方法在框架的源代码中,最好不要直接修改,我们可以在它注册完之后再重新注册一个覆盖它。可以加在bootstrap/app.php中,Application实例化之后。代码如下:

set_error_handler(function ($level, $message, $file = '', $line = 0) {
    if ($level == E_NOTICE || $level == E_WARNING) {
        Log::warning("PHP NOTICE or WARNING; MSG:[$message]", ['file' => $file, 'line' => $line]);
        return;
    }
    if (error_reporting() & $level) {
        throw new ErrorException($message, 0, $level, $file, $line);
    }
});

注意,代码中因为使用了Log这个Facades,因此必须放在$app->withFacades()之后
至此,NOTICE和WARNING不会产生烦人的日志,也不会搞挂请求,并且也保留了有效的提示信息。:)