发布新日志

  • php-一个页面响应未完成时,另一页面无法继续操作(session死锁)

    2016-08-18 12:27:31

    php做了一个远程查询的功能,后台处理时间比较久,数据量大时,有可能到几十分钟;

    当PHP 处理大数据量操作时,不能及时操作完成,这时候又有访问其他控制器
    或者
    异步请求时候会造成session 死锁现象
    这时,必须在A页面处理完成后,B页面才可以继续处理;


    处理方案:
    在A页面上增加:session_write_close();
    这样就可以不干扰B页面继续处理了。
  • Php两种调用ssh的方法

    2016-08-16 09:18:38

     
    1.用key方式
    public function ssh_cmd($cmd)
    {
        $content = '';
        $host = "192.168.146.180";
       
        $connection = ssh2_connect($host,22,array('hostkey'=>'ssh-rsa'));
        if (!$connection)
            die('Connection failed');
        else
        {
            if(ssh2_auth_pubkey_file($connection, 'root','/root/.ssh/id_rsa.pub','/root/.ssh/id_rsa'))
            {
                $stream = ssh2_exec($connection, $cmd);
                $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);

                stream_set_blocking($stream, true);
                stream_set_blocking($errorStream, true);

                if ($stream === FALSE) 
                        die('Command exec failed!');
                else
                        $content = stream_get_contents($stream).stream_get_contents( $errorStream );

                fclose($stream);
                fclose( $errorStream );
            }
            else
            {
                die('Public Key Authentication Failed');
            }
        }
        return $content;
    }

    使用key方式时,需要在php执行服务器上,root用户执行ssh-keygen命令,生成建立安全信任关系的证书。
    [root@Client root]# ssh-keygen -b 1024 -t rsa
    把生成的 /root/.ssh/id_rsa.pub 中的内容,追加到 ssh连接的服务器 /root/.ssh/authorized_keys 文件后;
    php执行服务器上,ssh连接测试:ssh -o GSSAPIAuthentication=no 192.168.146.180
    连接成功,表示安全信任关系配置完成;

    执行php过程中,如果提示:
    Warning: ssh2_auth_pubkey_file(): Authentication failed for root using public key: Unable to open public key file
    表示php执行用户无权限访问/root/.ssh/id_rsa.pub&id_rsa
    解决方法可参照:http://www.php.net/manual/en/function.ssh2-auth-pubkey-file.php

    另外创建一个目录来存放证书信息,如:
    mkdir /home/.ssh
    cp -af /root/.ssh/id_rsa /home/.ssh/      
    cp -af /root/.ssh/id_rsa.pub /home/.ssh/
    chmod 777 /home/.ssh -R
    修改ssh2_auth_pubkey_file中路径位置,再重试;

          
    2.用密码方式

    public function ssh_cmd($cmd)
    {
        $content = '';
        $host = "192.168.146.180";
        $hostuser = "root";
        $sshpasswd = "123456";
        $connection = ssh2_connect($host,22);

        if (!$connection)
                die('Connection failed');
        else
        {
            if(ssh2_auth_password($connection, $hostuser, $sshpasswd))
            {
                $stream = ssh2_exec($connection, $cmd);
                $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);

                stream_set_blocking($stream, true);
                stream_set_blocking($errorStream, true);

                if ($stream === FALSE) 
                        die('Command exec failed!');
                else
                        $content = stream_get_contents($stream).stream_get_contents( $errorStream );

                fclose($stream);
                fclose( $errorStream );
            }
            else
            {
                die('Public Key Authentication Failed');
            }
        }
        return $content;
    }
        
  • tctmgr支持的命令和参数-zt

    2016-07-11 17:45:35

    转自:http://blog.csdn.net/leonzhang2008/article/details/5407051

    tctmgr支持的命令和参数

        tctmgr create [-tl] [-td|-tb|-tt|-tx] path [bnum [apow [fpow]]]   
        创建数据库  
        
        tctmgr inform. [-nl|-nb] path  
        输出数据库的统计信息
       
        tctmgr put [-nl|-nb] [-sx] [-dk|-dc|-dai|-dad] path pkey [cols ...]  
        创建记录  
       
        tctmgr out [-nl|-nb] [-sx] path pkey  
        删除记录 
       
        tctmgr get [-nl|-nb] [-sx] [-px] [-pz] path pkey  
        通过主键查询记录 
       
        tctmgr list [-nl|-nb] [-m num] [-pv] [-px] [-fm str] path  
        输出所有记录
        -pv:显示所有详情;-m num:显示记录条数
       
        tctmgr search [-nl|-nb] [-ord name type] [-m num] [-sk num] [-kw] [-pv] [-px] [-ph] [-bt num] [-rm] [-ms type] path [name op expr ...]  
        通过自定义条件查询记录  
        例:tctmgr search test.tct date NUMBT 1383235200,1385827199 folder STREQ cur
       
        tctmgr optimize [-tl] [-td|-tb|-tt|-tx] [-tz] [-nl|-nb] [-df] path [bnum [apow [fpow]]]  
        优化数据库 
       
        tctmgr setindex [-nl|-nb] [-it type] path name  
        设置索引  
       
        tctmgr importtsv [-nl|-nb] [-sc] path [file]  
        Store records of TSV in each line of a file.  
        #导入TSV
        #tsv文件是以tab分隔的文件,例: key1/tvalue1/n
        例:tchmgr importtsv test.tct tsv.txt   
       
        tctmgr version  
        Print the version information of Tokyo Cabinet. 

       
    附查询条件表达式(前面加~,相当于标准sql中的非)

        STREQ :完全包含字符串,相当于标准sql中的where 字段=‘字符串’
        STRINC :包含此字符串,相当于标准sql中like ‘*字符串*’
        STRBW :以此字符串开头的内容,相当于标准sql中like ‘字符串*’
        STREW :以此字符串结尾的内容,相当于标准sql中like ‘*字符串’
        STRAND :包含在某区间内的内容,如标准sql中like ‘a-z’,那么他只能是a到z的字母
        STROR :不包含在某区间内的内容,如标准sql中like ‘!a-z’,那么他只能是数字或其他的符号
        STRRX :组合式结构,如标准sql中like “a“!b-m”#”
        NUMEQ :数值大小一样 相当于标准sql中 where a=‘1’
        NUMGT :数值大于某一值 相当于标准sql中 where a>‘1’
        NUMGE :数值大于等于某一值 相当于标准sql中 where a>=‘1’
        NUMLT :数值小于某一值 相当于标准sql中 where a<‘1’
        NUMLE :数值小于某一值 相当于标准sql中 where a<=‘1’
        NUMBT :数值处于某一数值区间,相当于标准sql中 where a> 1 and a < 10
        NUMOREQ :数值不处于某一数值的区间,如果是a大于1,小于10的话,那这个表达式右边的内容应该相当于标准sql中 where a< 1 or a > 10
        
  • C语言字符串处理函数sscanf-PS:loadrunner中使用不错

    2016-01-04 09:28:43

    最近在做IMAP脚本开发,需要处理一些返回值
    在WEB及winsocket协议中,都可以使用关联函数获取对应的返回值
    IMAP脚本中,没找到相关的处理函数

    只能考虑使用C语言的字符串处理函数了
    原来一直尝试用一些strstr类似的字符串处理函数来处理,发现不太方便

    直到看到sscanf函数,太太方便了!!
    特此记录!!

    =============================================================
    参考资料:
    http://baike.baidu.com/link?url=_jA4axxsGwfhftpuMnETtCt5-KpH7N_Tpn_SO48Dr-2nXX6yCUEiXjN-fw5cMuZChBeyfT8cYz7x6Vptw_0CWq
    http://www.cnblogs.com/lyq105/archive/2009/11/28/1612677.html


    sscanf() - 从一个字符串中读进与指定格式相符的数据。

    函数原型:
    int sscanf( const char *, const char *, ...);
    int sscanf(const char *buffer,const char *format,[argument ]...);
    buffer存储的数据
    format格式控制字符串
    argument 选择性设定字符串
    sscanf会从buffer里读进数据,依照format的格式将数据写入到argument里。

    头文件:
    #include<stdio.h>


    返回值:

    成功则返回参数数目,失败则返回-1,错误原因存于errno中。
    经多次测试,在linux系统中成功返回的是成功转换的值的个数,例如:
    sscanf("1 2 3","%d %d %d",buf1, buf2, buf3); 成功调用返回值为3,即buf1,buf2,buf3均成功转换。
    sscanf("1 2","%d %d %d",buf1, buf2, buf3); 成功调用返回值为2,即只有buf1,buf2成功转换。
    (注意:此处buf均为地址)

    说明:
    sscanf与scanf类似,都是用于输入的,只是后者以键盘(stdin)为输入源,前者以固定字符串为输入源。
    第二个参数可以是一个或多个 {%[*] [width] [{h | I | I64 | L}]type | ' ' | '\t' | '\n' | 非%符号}
    注:
    1、 * 亦可用于格式中, (即 %*d 和 %*s) 加了星号 (*) 表示跳过此数据不读入. (也就是不把此数据读入参数中)
    2、{a|b|c}表示a,b,c中选一,[d],表示可以有d也可以没有d。
    3、width表示读取宽度。
    4、{h | l | I64 | L}:参数的size,通常h表示单字节size,I表示2字节 size,L表示4字节size(double例外),l64表示8字节size。
    5、type :这就很多了,就是%s,%d之类。
    6、特别的:%*[width] [{h | l | I64 | L}]type 表示满足该条件的被过滤掉,不会向目标参数中写入值
    失败返回0 ,否则返回格式化的参数个数


    支持集合操作:

    %[a-z] 表示匹配a到z中任意字符,贪婪性(尽可能多的匹配)
    %[aB'] 匹配a、B、'中一员,贪婪性
    %[^a] 匹配非a的任意字符,并且停止读入,贪婪性


    例子:

    1. 常见用法。
    char buf[512] = ;
    sscanf("123456 ", "%s", buf);
    printf("%s\n", buf);
    结果为:123456
    2. 取指定长度的字符串。如在下例中,取最大长度为4字节的字符串。
    sscanf("123456 ", "%4s", buf);
    printf("%s\n", buf);
    结果为:1234
    3. 取到指定字符为止的字符串。如在下例中,取遇到空格为止字符串。
    sscanf("123456 abcdedf", "%[^ ]", buf);
    printf("%s\n", buf);
    结果为:123456
    4. 取仅包含指定字符集的字符串。如在下例中,取仅包含1到9和小写字母的字符串。
    sscanf("123456abcdedfBCDEF", "%[1-9a-z]", buf);
    printf("%s\n", buf);
    结果为:123456abcdedf
    5. 取到指定字符集为止的字符串。如在下例中,取遇到大写字母为止的字符串。
    sscanf("123456abcdedfBCDEF", "%[^A-Z]", buf);
    printf("%s\n", buf);
    结果为:123456abcdedf
    6、给定一个字符串iios/12DDWDFF@122,获取 / 和 @ 之间的字符串,先将 "iios/"过滤掉,再将非'@'的一串内容送到buf中
    sscanf("iios/12DDWDFF@122", "%*[^/]/%[^@]", buf);
    printf("%s\n", buf);
    结果为:12DDWDFF
    7、给定一个字符串““hello, world”,仅保留world。(注意:“,”之后有一空格)
    sscanf(“hello, world”, "%*s%s", buf);
    printf("%s\n", buf);
    结果为:world
    %*s表示第一个匹配到的%s被过滤掉,即hello被过滤了
    如果没有空格则结果为NULL。
    8、最简明的格式是tab间隔的字符串  
    sscanf(“字符串1\t字符串2\t字符串3”,"%s%s%s",str1,str2,str3);
    printf("%s\t%s\t%s\n",str1,str2,str3);
    结果为:字符串1 字符串2 字符串3
  • JSP页显示当前几种格式的日期方法

    2009-02-05 14:53:25

    JSP页显示当前几种格式的日期方法!
    第一种方式:
    [list=1][html]  
  • [head][title]取得系统时间[/title][/head]   [body]  
  • [%java.util.Date date=new java.util.Date();%]   现在是:<%=date%>  
  • [/body]   [/html]  
  • 运行结果:   现在是:Tue Jul 31 10:32:52 CST 2001  
      第二种方式:
      [list=1][%@ page import="java.util.*, java.text.*" %]  
    • [HTML]   [HEAD][TITLE]显示当前时间
    • [BODY]   当前时间:  
    • [%   Date now = new Date();  
    • out.println(DateFormat.getTimeInstance().format(now));   %]  
    • [/BODY]   [/HTML]  
    • 运行结果:   10:31:42 AM  
        第三种:
        [list=1][%  
      • java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy年MM月dd日");   java.util.Date currentTime_1 = new java.util.Date();  
      • out.print(formatter.format(currentTime_1));   %]  
      • 运行结果:   2001年07月31日  
          第四种:
          java 代码[list=1][%  
        • java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy/MM/dd HH/mm/ss");   java.util.Date currentTime_1 = new java.util.Date();  
        • out.print(formatter.format(currentTime_1));   %]  
        • 运行结果:   2001/07/31 10/32/52  
            其中:第三四两种方式其实是一样的他可以产生千变万化的格式。 
          • HTTP Error Codes -zt

            2009-01-13 10:10:55

            普遍的www服务器的网络连接,都用的是http协议,在这里我们如果对http状态字(http status)进行适当的了解有一定的帮助.

            http error codes

            400 invalid syntax. 语法问题
            401 access denied. 访问拒绝
            402 payment required. 必须完整
            403 request forbidden. 请求被禁止
            404 object not found. 对象没有找到
            405 method is not allowed. 方法不允许
            406 no resp acceptable to client found. 客户端没有响应
            407 proxy authentication required. 代理需要验证
            408 server timed out waiting for request. 等等请求时服务器断开连接
            409 user should resubmit with more info. 有冲突用户应该进行检查
            410 resource is no l available. 资源不可用
            411 server refused to accept request without a length. 服务器拒绝接受没有长度的请求
            412 prec given in request failed. 放弃请求失败的条件
            413 request entity was too large. 请求太大
            414 request uniform resource identifier (uri) too long. 请求的uri 太长
            415 unsupported media type. 不支持media类型
            449 retry after doing the appropriate action. 在作了适当动作后重试
            500 internal server error. 服务器内部错误
            501 server does not support the functi required to fulfill the request. 服务器不支持请求的功能
            502 error resp received from gateway. 从网关收到错误应答
            503 temporarily overloaded. 过载
            504 timed out waiting for gateway. 等待网关时请求断开
            505 http version not supported. 不支持http的版本


            http status codes returned by servers on the internet.
            从internet返回的http status代码(http 状态字)
            http_status_continue (100)
            the request can be continued.
            请求不能被继续
            http_status_switch_protocols (101)
            the server has switched protocols in an upgrade header.
            通过新的header服务器的协议被转换了
            http_status_ok (200)
            the request completed successfully.
            请求成功的完成
            http_status_created (201)
            the request has been fulfilled and resulted in the creation of a new resource.
            通过新的资源请求已经被完成
            http_status_accepted (202)
            the request has been accepted for processing, but the processing has not been completed.
            请求已经被接受处理,但是处理还没有完成
            http_status_partial (203)
            the returned meta information in the entity-header is not the definitive set available from the origin server.
            从服务器返回的在entity-header中的meta信息是无效的
            http_status_no_content (204)
            the server has fulfilled the request, but there is no new information to send back.
            服务器实现了请求,但是没有返回信息
            http_status_reset_content (205)
            the request has been completed, and the client program should reset the document view that caused the request to be sent to allow the user to easily initiate another input action.
            请求已经被完成,并且web程序(客户端程序浏览器程序)已经重置了文档视图目录(c
            http_status_partial_content (206)
            the server has fulfilled the partial get request for the resource.
            服务器已经为资源完成了部分get请求
            http_status_ambiguous (300)
            the server couldn't decide what to return.
            服务器不能判定返回什么
            http_status_moved (301)
            the requested resource has been assigned to a new permanent uri (uniform resource identifier), and any future references to this resource should be d using of the returned uris.
            被请求的资源已经被分配给新的uri,并且以后引用时都使用这个uris资源。
            http_status_redirect (302)
            the requested resource resides temporarily under a different uri (uniform resource identifier).
            请求的资源临时在不同的uri下
            http_status_redirect_method (303)
            the resp to the request can be found under a different uri (uniform resource identifier) and should be retrieved using a get http verb on that resource.
            请求的资源不能在不同的uri下找到,并且从新使用get http在服务器上从新检索
            http_status_not_modified (304)
            the requested resource has not been modified.
            请求的资源没有被改变
            http_status_use_proxy (305)
            the requested resource must be accessed through the proxy given by the location field.
            请求的资源必须通过特定的代理获得
            http_status_redirect_keep_verb (307)
            the redirected request keeps the same http verb. http/1.1 behavīor.
            从定位请求,
            http_status_bad_request (400)
            the request could not be processed by the server due to invalid syntax.
            因为语法不能被服务器处理
            http_status_denied (401)
            the requested resource requires user authentication.
            请求资源命令必须被验证(拒绝访问)
            http_status_payment_req (402)
            not currently implemented in the http protocol.
            没有完全实现http协议
            http_status_forbidden (403)
            the server understood the request, but is refusing to fulfill it.
            服务器理解了请求,但是拒绝完成他
            http_status_not_found (404)
            the server has not found anything matching the requested uri (uniform resource identifier).
            没有找到任何被指定的uri

            http_status_bad_method (405)
            the http verb used is not allowed.
            http动作不被允许
            http_status_none_acceptable (406)
            no resp acceptable to the client were found.
            应答没有被客户接受
            http_status_proxy_auth_req (407)
            proxy authentication required.
            代理必须被验证
            http_status_request_timeout (408)
            the server timed out waiting for the request.
            服务器在等待请求时中止了
            http_status_conflict (409)
            the request could not be completed due to a c with the current state of the resource. the user should resubmit with more information.
            请求不能被完成,问题是资源冲突。用户应该进行调整
            http_status_gone (410)
            the requested resource is no l available at the server, and no forwarding address is known.
            请求的资源在服务器上不再可用,而且没有转发地址
            http_status_length_required (411)
            the server refuses to accept the request without a defined c length.
            服务器拒绝接受没有定义目录大小的请求
            http_status_precond_failed (412)
            the prec given in or more of the request header fields evaluated to false when it was tested on the server.
            当在服务器上测试请求头文件放弃一个或者多个请求的条件
            http_status_request_too_large (413)
            the server is refusing to process a request because the request entity is larger than the server is willing or able to process.
            服务器拒绝处理请求,原因是请求的大小超过服务器能够处理的大小
            http_status_uri_too_long (414)
            the server is refusing to service the request because the request uri (uniform resource identifier) is l than the server is willing to interpret.
            服务器拒绝服务,原因是请求的uri超过了服务器能够揭示的长度
            http_status_unsupported_media (415)
            the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
            服务器拒绝服务,原因是请求格式不被支持
            http_status_retry_with (449)
            the request should be retried after doing the appropriate action.
            在作了适当的动作后请求被重试
            http_status_server_error (500)
            the server encountered an unexpected c that prevented it from fulfilling the request.
            服务器遇到请求失败意外
            http_status_not_supported (501)
            the server does not support the functi required to fulfill the request.
            服务器不支持必须完成请求的功能
            http_status_bad_gateway (502)
            the server, while acting as a gateway or proxy, received an invalid resp from the upstream server it accessed in attempting to fulfill the request.
            服务器当作为网关或代理时,从上行服务器接受的响应请求失败
            http_status_service_unavail (503)
            the service is temporarily overloaded.
            服务器负载
            http_status_gateway_timeout (504)
            the request was timed out waiting for a gateway.
            等待网关时请求断开,没有响应
            http_status_version_not_sup (505)
            the server does not support, or refuses to support, the http protocol version that was used in the request message.
            服务器不支持或者拒绝支持正在使用请求的http协议的版本

          • VC6中调用DLL动态库

            2009-01-08 11:14:45

            VC6中调用DLL动态库:

            使用前要先声明函数:

            typedef int (WINAPI * PFN_CONNECT)(char * strHost, char * strUser,char * strPassword, char * strDb);

            typedef int (WINAPI * PFN_GETDATA)(char *str_query,struct process_data *head);

             

            函数中调用部份:

                HMODULE  hDLL;
                PFN_CONNECT pFunc_connect = NULL;
                PFN_GETDATA pFunc_getdata = NULL;
                hDLL = LoadLibrary("MonitorTest.dll");
                pFunc_connect = (PFN_CONNECT)GetProcAddress(hDLL,"init_mysql_connection");
                pFunc_getdata = (PFN_GETDATA)GetProcAddress(hDLL,"get_mysql_full_processlist_data");
                int res=0;
                res =(int) pFunc_connect("localhost","root","111111","mysql");

                res =(int) pFunc_getdata("show full processlist;",&struct_out);

             

               ……

             FreeLibrary(hDLL);

              ……

          Open Toolbar