PHP

浏览模式: 标准 | 列表 | 图文

连接mq出现2538、2539错误

最近在一个合作项目中需要连接ibm的websphere,经常连着连着就报错了。

比如2533错误:Reason:2033 Text:No message available. 没信息了。。。。

再比如2538错误:Connx CompCode:2 Reason:2538 Text:An MQCONN call was issued from a client to connect to a queue manager but the attempt to allocate a conversation to the remote system failed

这2538就是TMD连接不上服务器,后来问了对方,原来,对方挂了。我晕

今天又是2538,再一问,我靠,换IP了。。真受不了

然后改好IP,再连接,结果。。。2539出现了:Reason:2539 Text:An MQCONN call was issued from a client to connect to a queue manager but the attempt to establish communication failed

查了下2539对应的错误:

2539 (09EB) (RC2539): MQRC_CHANNEL_CONFIG_ERROR

Explanation

An MQCONN call was issued from a client to connect to a queue manager but the attempt to establish communication failed. Common causes of this reason code are:

a.The server and client cannot agree on the channel attributes to use.
b.There are errors in one or both of the QM.INI or MQCLIENT.INI configuration files.
c.The server machine does not support the code page used by the client.

有三种可能。。。现在就等对方折腾了。不过查了下,关于第三种,code page不一样的错误,在http://www.cnblogs.com/fromchaos/archive/2010/02/24/1672736.html,有个解释。为了方便我就复制部分东西过来了

选择客户机或服务器编码字符集标识(CCSID)

客户机代码假设通过客户机中 MQI 的字符数据位于机器所配置的 CCSID 中。如果此 CCSID 是一个不支持的 CCSID 或不是必需的 CCSID,可以用 MQCCSID 环境变量覆盖它,例如,在 Windows® 上:

SET MQCCSID=850
更新开始或者,在 UNIX® 系统上:
export MQCCSID=850

如果是CCSID的问题我只要加在rc.local就好了,不过目前还不知道对方是不是这个错误。。。最后再转一下上述文章的最后一段,关于CCSID的说明

IBM Coded Character Set Identifiers (CCSID)码表

A CCSID is a Coded Character Set Identifier. The Unicode standard defines a Coded Character Set as "A character set in which each character is assigned a numeric code value." This means that a CCSID is a number that defines a numeric ordering of characters. The IBM ® Character Data Representation Architecture (CDRA) as defined in SC09-1390, defines CCSIDs that are used with IBM to represent character data. This architecture defines Single Byte Character Set (SBCS) CCSIDs, Multiple Byte Character Set (MBCS) CCSIDs, and Mixed CCSIDs which are a combination of SBCS and MBCS data. MBCS CCSIDs are usually used for languages, such as Chinese, Japanese, and Korean, that define a larger number of characters than can be represented in a single byte.
CCSID是一个字符集的标识。作为unicode标准通过定义一个字符集内每个字符要对应那个数字值的方式定义了一个字符集。这说明CCSID就是一个定义字符集顺序的标识数码罢了。IBM的字符标识架构在文档 SC09-1390(http://www-304.ibm.com/jct03002c/software/globalization/cdra/index.jsp;http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/FOCREF00/CCONTENTS)中做了定义,CCSID是IBM用来标识字符序列的标识代码。这个架构定义了SDCS(单字符集)的CCSID值,MBCS(多字符集)的CCSID值和混合单字符多字符集的混合CCSID值。多字符集的CCSID一般用于语言,比如中文,日文,韩文,这些语言的字符量很大,无法用单字节的码值来代表。

All SBCS CCSIDs define a similar basic set of characters, although they might define them in different numeric ordering. For instance all SBCS EBCDIC CCSIDs define the number "1" as x'F0' and all SBCS ASCII CCSIDs define the number 1 as x'30'.

CCSID间的转换有多种类型。其中一种转换就是从一种CCSID到另一种CCSID的转换,举例来说从ASCII(CCSID 1252)到EBCDIC(CCSID 37)。另一种是从串数据到另一种数据类型的转换。举例来说转换字符串数据到数值。在所有的这种类型的转换中都必须标识CCSID值来保证转换的正确进行。

但是转换是有要求的,第一种转换的前提是转到的 CCSID的类型中要包含转换前的CCSID类型中要转换的字符,比如,如果从CCSID1381(S-CHGBPC-DATA) 类型的简体中文的PC编码中的一个中文字符"中"字到其他CCSID编码转换到的编码起码要求这个CCSID编码的字符集中包含同样的"中"字。

我从IBM找到的对CCSID说明的列表如下:

摘录自http://www-304.ibm.com/jct03002c/software/globalization/ccsid/ccsid_registered.jsp,如果需要详细信息,请自行查询。

做个笔记,从去年开始,不停的在与第三方对接程序。有时候真心想骂娘,后来想想,大家都是混口饭吃嘛。而且人家还是上游单位,混的比你好多了。。不要与他们一般见识 。

typecho Stat 插件的小BUG

typecho Stat 插件的小BUG

在使用Stat插件时,发现代码中存在一个小BUG,是对Columns not found的判断有问题,原代码写的是:

'Mysql' == $type && 1051 == $code

但事实上,如果你使用的是PDO,$code 还应该加上 42S22,所以上述代码就应该改成这样了

('Mysql' == $type && (1054 == $code || $code == '42S22'))

然后就可以安装成功了。

该插件的信息是:

/**
* 页面浏览次数统计插件
* @package Stat
* @author Hanny
* @version 1.0.2
* @dependence 10.8.15-*
* @link http://www.imhan.com
* 历史版本
* version 1.0.2 at 2010-07-03
* 终于支持前台调用了
* 接口支持Typecho 0.8的计数
* 增加SQLite的支持
* version 1.0.1 at 2010-01-02
* 修改安装出错处理
* 修改安装时默认值错误
* version 1.0.0 at 2009-12-12
* 实现浏览次数统计的基本功能

*/

不过由于这个版本比较早,就将就一下啦

让人吃药的max_input_vars

让人吃药的max_input_vars

在某个项目中,每次提交都丢了部分数据,觉得非常奇怪,开始的时候以为是数据量过大,但后来又觉得不应该,因为如果是数据量过大,要么就是提交失败,要么就是直接报错啊?

但事实上我每次提交都是成功的,但print_r($_POST)的时候,总丢了不少的数据,这是为什么呢?

于是,将http头中的form内容全部copy出来,查看了一下,发现共是1200多行。打印POST的时候,只有1000行,咦,这不科学啊?少了200多行?

google了一下,原来,PHP有这么一个配置:

; How many GET/POST/COOKIE input variables may be accepted
; max_input_vars = 1000

而它的默认值 是1000,好吧,如果不是这次意外,根本不会发现项目中存在的这个BUG,毕竟要提交1000多个参数还是有难度的。顺便说一下:param[]=1&param[]=2是属于两个参数。所以如果你提交的项目中有多个数组,每个数组又有不少值的话,你就真的要小心了

手贱,将max_input_vars 改成5000,问题解决。。

------

回顾,这种因为偷懒的事情往往出现在哪里呢?

1、ajax提交,不管三七二十一,将某堆数据 serializeArray(),jquery的这个功能,偶尔真心会让人吃药。

2、日程管理和广告排期管理,这时候input的key确实 有可能会超过1000,但我还是建议先序列化再存到一个字段提交更安心 吧?

------
OVER

thinkphp模板中的Load好象有BUG

thinkphp模板中的Load好象有BUG

在thinkPHP的模板中,有几个tag标签都是用来引入js和css的,比如:import/css/js/load之类的,经过测试,好象load这个Tag有BUG

比如:<load href="/assets/static/wap/css/reset.css"/>,加载一个CSS文件,这个没问题,但如果使用<load href="/assets/static/wap/css/reset.css?ver=1"/>,这种就直接失效了。

当然如果你使用<css file="xxxx?ver=1" />是有效的

看了下代码,好象在没有明确标记类型的时候,程序判断后缀名失效了。<css>标签是主动告诉import程序,我的类型是css,而load是根据代码判断的,因此,对于load应该主动加上type="css",或者,修改程序:

看划线的地方,这里应该先basename,把?或者其他带有版本的信息先去除干净才OK。

或许这是一个bug,或许,就是提示你应该主动加类型。

如何解决wordpress后台打开超慢的总是

如何解决wordpress后台打开超慢的总是

最近有些朋友和我说,wordpress的后台在本地打开都超慢。不知道为什么,负载什么的都没有。

看了下代码,同时也看了下网络上的评论,原来最近大家都喜欢上了使用google的字体,众所周知,google的各种服务在国内访问都是渣渣,真不知道怎么会有这样的公司,明明这个网站就打不开,还有那么多人用它的东西。当然你懂的
既然知道问题在哪里就好办了。
1、插件法
现在针对上述情况,国内开发人员已经开发了相应的插件来处理了,如disable google fonts或者其他的,你搜索google fonts就可以
2、代码法
在wp-include/script-loader.php中,你会找到font.googleapis.com的字样。你只要替换掉它们即可(当然,删除也可以),如果你有需要用这些字体,你可以用数字公司提供的前端CDN库(http://libs.useso.com/)。到了上述的网址我相信你也应该知道怎么了。
不知道何时才能打开那些网站,这些就当成技巧先保留着吧
被两个问题搞死。。

被两个问题搞死。。

今天被两个问题搞死

1、加载hprose.phar/HproseHttpServer.php一直报文件找不到:Warning: include(./hprose.phar/HproseHttpServer.php): failed to open stream: No such file or directory
2、定义了Yii的errorHandler和error的Controller结果死活不对。
解决:
1、居然是忘了phar在include的时候要申明协议,即include('hprose.phar/xxx.php')是不对的。必须要include("phar://hprose.phar/xxx.php");
该死的,居然忘了这个,命令行下写代码,总是搞错东西
2、这个问题说实在的。真TMD操蛋,我是想偷懒的,所以就加载了yiit.php。。想着这是个lite的文件,应该没啥问题啊?结果,就是因为加载的yiit.php而不是yii.php搞得我在那里折腾了半天。真是要人命啊
果然就象老王说的,每一个找寻半天不得结果的BUG后面,都有一个令人啼笑皆非的原因
php的curl函数怎么样请求https的网站

php的curl函数怎么样请求https的网站

说起curl请求https的网站,网上的教程很多,无非都是说在你没有证书的情况下,加上下面两句就可以了

<?php
curl_setopt_array($handle, array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,

));
诚然,很多人在这么处理后就OK了,但我遇到的情况不一样,这两个加上之后,还是不能访问。
于是问了vampire,他让我试了一下在命令行下加参数访问,如:curl -3 https://xxxxx.com,顺利的得到了结果,https还是有version的。于是在上述的脚本里再加上一句:
CURLOPT_SSLVERSION => 3,
指定sslversion。
当然,这个值 不一定是3,只是我正好是在version为3的情况下访问正常罢了。实际情况还需实际对待。
话说回来,我在curl在访问的时候报的错是:
curl: (35) error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:reason(1112)
Over。
ThinkPHP的主从数据库配置

ThinkPHP的主从数据库配置

最近涉及到的项目中用到了thinkphp,我都N年没有碰过这玩意了。但现在还是需要用一用。正好那些能够下载得到的wxcms也可以用这个来优化一下性能。。其实我就一台服务器。装逼而已

于是转一下别人的文章,因为他其中特别写了一句:只要是exec就一定从主库走,query一定从从库走。所以建议query中不要有实际的更新和插入操作。以防万一
原文地址:http://www.verydemo.com/demo_c327_i782.html
前言:
Thinkphp 框架本身是支持读写分离的,如何做呢?
最简单的做法是在配置文件中修改:
'DB_TYPE'=> 'mysql',
'DB_DEPLOY_TYPE' => 1, //开打支持多服务器
'DB_RW_SEPARATE'=>true, //读写<strong>分离</strong>分开
'DB_HOST'=> '192.168.100.78,192.168.100.60', // 数据库服务器地址 master(写)/slave(读)
'DB_NAME'=>'test',
'DB_USER'=>'root',
'DB_PWD'=>'root',
'DB_PREFIX' => 'fav_',
默认第一台数据库78是主数据库,负责写入操作,第二台60负责读操作,Thinkphp 会自动识别读和写,然后分配链接对应的数据库,来达到读写分离的效果。
注意事项:
1. 如果要设置分布式数据库,暂时不支持DB_DSN方式配置。
2.如果你当前采用了分布式数据库,并且设置了读写分离的话,query方法始终是在读服务器执行,因此query方法对应的都是读操作,而不管你的SQL语句是什么。
3.如果你当前采用了分布式数据库,并且设置了读写分离的话,execute方法始终是在写服务器执行,因此execute方法对应的都是写操作,而不管你的SQL语句是什么。
因此,'DB_DSN'=> 'mysql:host=192.168.100.60;dbname=51fanli_cang', 这种方式不支持主从分离,需要改。
当采用原生态的sql语句进行写入操作的时候,要用execute,读操作要用query,切记,否则乱掉了。
搞定!
---EOF---
转:MQ+PHP – Linking IBM’s WebSphere MQ to PHP

转:MQ+PHP – Linking IBM’s WebSphere MQ to PHP

我在上一篇博客在centos下处理PHP+WebSphere客户端中提到了一个英文网站:http://blog.phpdeveloper.org/?p=140,我也是参考它才完成了最终的配置,为此我也写了中文的说明,但感觉文笔不行,所以我还是贴上原文吧:

During a recent project at work I had to get PHP linked with IBM’s WebSPhere MQ software we have running on another internal server. Our goal was to use our existing web service to take the requests from external vendors and push their XML data back into the queue inside our firewall. Thankfully there’s an extension in PECL that does just that.

Here’s the basic steps I took – hopefully it’ll be useful to someone else out there in the same spot I was. This all assumes you’re working on a web server that doesn’t have an MQ server installed already:

  • Get the extension: Head over to the PECL page for mqseries and download the latest version. Unpack it into a directory on your local server
  • Get the MQ client libs: You’ll need to go to IBM’s website to download the latest client/libraries for your install (you’ll need an IBM ID to get to the downloads):
    • Go to the IBM page for the MQ client listing
    • Look for the “WebSphere MQ Clients” link under the “Related products and technologies” section and click on it
    • Scroll down to the “Download Package” section and choose from one of the mirror locations
    • Select your package from the list (I went with “Linux for System x86″ for our setup)
    • Click on the download link and fill out some required information (you didn’t think you were getting off that easy, did you?)
    • Agree to the terms and conditions and you’ll get a “Download Now” link
    • Drop the archive file (tar, tar.gz, etc) into your server and unpack into a temporary directory (mine had an issue unpacking into the local directory, not a subdirectory)
  • Install the package(s): Once you have the IBM software extracted, you should have a series of packages. You’ll need to install the “MQSeriesSDK” to get the right libraries in place to compile the PHP extension
  • Build the mqseries extension: Go into the mqseries directory and run “phpize”, “./configure” and “make” to create the .so file. The process should drop it into the default extensions directory.
  • If needed, move it: Be sure that the shared module for the extension is in the right directory for the PHP install to find it. (You can make a phpinfo() page if you’re not sure where that is.)
  • Update your php.ini: Add in a line to include the extension in your current setup. Remember, after any changes to the php.ini, you need to restart the web server.

Now for the fun part – if everything’s working and the extension shows up in your phpinfo() as active, give this script a shot and see if you can connect to your MQ server:

1 $mq_host_ip ='127.0.0.1';
2 $queue_name = 'HOST.REMOTE.Q';
3 $mq_server = 'WBRK_QM_U49';
4 $mqcno = array(
5 'Version' => MQSERIES_MQCNO_VERSION_2,
6 'Options' => MQSERIES_MQCNO_STANDARD_BINDING,
7 'MQCD' => array(
8 'ChannelName' => 'CLIENT.CHANNEL',
9 'ConnectionName' => $mq_host_ip,
10 'TransportType' => MQSERIES_MQXPT_TCP
11 )
12 );
13
14 // Connect to the MQ server
15 mqseries_connx($mq_server,$mqcno,$conn,$comp_code,$reason);
16 if ($comp_code !== MQSERIES_MQCC_OK) {
17 trigger_error('Cannot open connection to server: '.$mq_server,E_USER_ERROR);
18 }else{
19 echo 'Connection good!';
20 }

Obviously you’ll need to adjust the settings to fit your server, but at least this gives you a start.

--END

在centos下处理PHP+WebSphere客户端

在centos下处理PHP+WebSphere客户端

事先申明。我是借鉴了这篇博客:http://blog.phpdeveloper.org/?p=140

当然在其中遇到了不少问题,我在这里一一说明:
1、准备工作
a. pecl mqseries :http://pecl.php.net/package/mqseries
b. ibm mq client: http://www-01.ibm.com/software/integration/wmq/clients/
2、步骤:
1、先安装ibm mq client :下载地址最终是要翻墙的,我这里不教翻墙技术。下载完后,解开压缩,在centos下面,直接rpm -ivh
MQSeriesRuntime-7.5.0-3.x86_64.rpm,和rpm -ivh MQSeriesSDK-7.5.0-3.x86_64.rpm ,由于我们只是当成一个client库来连接,因此安装这两个就够了
2、编译mqseries。在这里我吃药了,我下载的是0.14版的,我一看更新时间是2014年。我想这是最新的总没问题吧。结果。。。./configure到最后的时候,说--with-libdir=lib64找不到,让我指定。可是我明明指定了也不能安装。于是google了一下,发现这曾经是一个BUG。在2012年解决掉了。在bug.php.net里。写的是bug fixed。所以我下载了0.13的,然后再安装,果然成功了
3、测试
<?php
$mq_host_ip ='127.0.0.1';
$queue_name = 'HOST.REMOTE.Q';
$mq_server = 'WBRK_QM_U49';
$mqcno = array(
'Version' => MQSERIES_MQCNO_VERSION_2,
'Options' => MQSERIES_MQCNO_STANDARD_BINDING,
'MQCD' => array(
'ChannelName' => 'CLIENT.CHANNEL',
'ConnectionName' => $mq_host_ip,
'TransportType' => MQSERIES_MQXPT_TCP
)
);

// Connect to the MQ server
mqseries_connx($mq_server,$mqcno,$conn,$comp_code,$reason);
if ($comp_code !== MQSERIES_MQCC_OK) {
trigger_error('Cannot open connection to server: '.$mq_server,E_USER_ERROR);
}else{
echo 'Connection good!';
}
$mq_server从手册上看得知这应该是:queue_manager,所以应该是manager的名称
如果你访问的mq不是默认的端口号,还要加上端口号。我在这里走了不少弯路。我原来connectionName是写成:127.0.0.1:1234,报错2387,意思是host not avarible。查了下资料,原来端口号应该是 ip(port),也就是说得:127.0.0.1(1234) 这样的形式才OK。于是改好后再测试就通过啦。
----
我是在一台干净的Centos上安装的。所以做了很多准备工作:
1、 yum install php php-devel(devel里面才有phpize)
2、yum install gcc gcc-c++ g++
然后在安装的时候还有提示:you will need re2c ...于是找到这个博客:http://denghai260.blog.163.com/blog/static/726864092012260242533/
里面说道:
wget http://sourceforge.net/projects/re2c/files/re2c/0.13.5/re2c-0.13.5.tar.gz/download
tar -zxvf re2c-0.13.5.tar.gz
cd re2c-0.13.5
./configure && make && make install
至此,遇到的所有的问题都解决了。