php-5.6.26源代码 - 如何用C语言支持“类似异常”机制

 

代码编写在文件php-5.6.26\Zend\zend.h
    #define zend_bailout()        _zend_bailout(__FILE__, __LINE__)
    
    #ifdef HAVE_SIGSETJMP
    #    define SETJMP(a) sigsetjmp(a, 0) // 设置跳转点
    #    define LONGJMP(a,b) siglongjmp(a, b) // 进行跳转
    #    define JMP_BUF sigjmp_buf
    #else
    #    define SETJMP(a) setjmp(a)
    #    define LONGJMP(a,b) longjmp(a, b)
    #    define JMP_BUF jmp_buf
    #endif
    
    #define zend_try                                                \
        {                                                            \
            JMP_BUF *__orig_bailout = EG(bailout);                    \
            JMP_BUF __bailout;                                        \
                                                                    \
            EG(bailout) = &__bailout;                                \
            if (SETJMP(__bailout)==0) { // 设置跳转点
    #define zend_catch                                                \
            } else {                                                \
                EG(bailout) = __orig_bailout;
    #define zend_end_try()                                            \
            }                                                        \
            EG(bailout) = __orig_bailout;                            \
        }
    #define zend_first_try        EG(bailout)=NULL;    zend_try
    
使用例子
    // 宏代码
    zend_try {
        /* 2 = Count of deprecation structs */
        for (i = 0; i < 2; i++) {
            const char **p = directives[i].directives;
    
            while(*p) {
                long value;
    
                if (cfg_get_long((char*)*p, &value) == SUCCESS && value) {
                    zend_error(directives[i].error_level, directives[i].phrase, *p);
                }
    
                ++p;
            }
        }
    } zend_catch {
        retval = FAILURE;
    } zend_end_try();
    
    // 宏展开
    {
        {                                                            
            JMP_BUF *__orig_bailout = EG(bailout);                    
            JMP_BUF __bailout;                                        
                                                                    
            EG(bailout) = &__bailout;                                
            if (SETJMP(__bailout)==0) {
                /* 2 = Count of deprecation structs */
                for (i = 0; i < 2; i++) {
                    const char **p = directives[i].directives;
            
                    while(*p) {
                        long value;
            
                        if (cfg_get_long((char*)*p, &value) == SUCCESS && value) {
                            zend_error(directives[i].error_level, directives[i].phrase, *p);
                        }
            
                        ++p;
                    }
                 }
             } else {                                                
                EG(bailout) = __orig_bailout;
             }                                                        
             EG(bailout) = __orig_bailout;                            
          }
    }
    

 

转载于:https://www.cnblogs.com/xiaoyaogege/p/8629063.html

tar zxvf php-5.6.37.tar.gz cd php-5.6.37 #添加组 groupadd www #添加php-fpm用户 useradd -c php-fpm-user -g www -M www # c和c++编译器 yum -y install -y gcc gcc-c++ # PHP扩展依赖 yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-fpm\ --with-fpm-user=www\ --with-fpm-group=www\ --enable-mysqlnd\ --with-mysql=mysqlnd\ --with-mysqli=mysqlnd\ --with-pdo-mysql=mysqlnd\ --enable-opcache\ --enable-pcntl\ --enable-mbstring\ --enable-soap\ --enable-zip\ --enable-calendar\ --enable-bcmath\ --enable-exif\ --enable-ftp\ --enable-intl\ --with-openssl\ --with-zlib\ --with-curl\ --with-gd\ --with-zlib-dir=/usr/lib\ --with-png-dir=/usr/lib\ --with-jpeg-dir=/usr/lib\ --with-gettext\ --with-mhash\ --with-ldap make && make install cp php.ini-production /usr/local/php/etc/php.ini cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # 设置php-fpm开机自动启动 chmod +x /etc/init.d/php-fpm chkconfig php-fpm on cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf service php-fpm start 设置php为全局命令: 修改/etc/profile文件使其永久性生效,并对所有系统用户生效, 在文件末尾加上如下两行代码: PATH=$PATH:/usr/local/php/bin //php命令路径 如果还要同时加入mysql 则第一句: PATH=$PATH:/usr/local/php/bin:/usr/local/mysql/bin //路径一定要正确 执行 命令source /etc/profile 使用php -V确认 【查看php-fpm端口】 vim /usr/local/php/etc/php-fpm.conf listen = 127.0.0.1:9000
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值