Submitted by gouki on 2014, July 5, 12:04 AM
最近涉及到的项目中用到了thinkphp,我都N年没有碰过这玩意了。但现在还是需要用一用。正好那些能够下载得到的wxcms也可以用这个来优化一下性能。。其实我就一台服务器。装逼而已
于是转一下别人的文章,因为他其中特别写了一句:只要是exec就一定从主库走,query一定从从库走。所以建议query中不要有实际的更新和插入操作。以防万一
原文地址:http://www.verydemo.com/demo_c327_i782.html
前言:
Thinkphp 框架本身是支持读写分离的,如何做呢?
最简单的做法是在配置文件中修改:
PHP代码
- 'DB_TYPE'=> 'mysql',
- 'DB_DEPLOY_TYPE' => 1,
- 'DB_RW_SEPARATE'=>true,
- 'DB_HOST'=> '192.168.100.78,192.168.100.60',
- '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---
Tags: thinkphp
PHP | 评论:0
| 阅读:22198
Submitted by gouki on 2014, July 5, 12:00 AM
标题其实没什么,主要原因是。我在两台机器上部署了同样的程序,一个访问的时候一直显示404,一个就一直正常。死活找不到原因
1、背景
两台服务器,都是CentOS,一个可以公网访问,一个只能内网访问,因此一个可以在浏览器里打开,一个只能用命令行访问,习惯性的,我使用了wget
2、浏览器访问正常,命令行显示404
3、配置完全一样,问题不明。
wget的时候显示404,无输出。。也就导致没有任何文件信息被下载
4、使用的YII框架。结果,记录的LOG,分组了只记录了system.db,404的LOG未被记录
5、调整策略:
a.用curl(有朋友建议)
b.把LOG改为全部记录
于是就发现问题了。LOG里显示无默认控制器。CURL直接输出错误信息
原来,WGET看到http头是404后就不再下载内容,即使我有在文件里有输出,而CURL默认就是按浏览器访问的显示而正常输出在屏幕上。
问题解决。记录一下。就因为WGET和CURL的默认机制不一样。吐血三升
Linux | 评论:1
| 阅读:19612
Submitted by gouki on 2014, June 9, 1:31 PM
积怨以久了。我不知道这个行为是怎么出来的。。。说说我的步骤和问题吧
1、我有一个淘宝帐号A,我有一个阿里妈妈帐号
2、我要登录阿里妈妈,阿里妈妈说你不能登录了,请使用淘宝帐号吧。在不明所以的情况下,翻看了阿里妈妈的N个帖子。学会了绑定,但是说不能绑定是卖家的帐号,或者曾经当过卖家的帐号。
3、重新注册一个新的淘宝帐号B(用邮箱注册因为我就一个手机,原来的帐号已经绑定手机了)。他们又顺便帮我开通了支付宝(真是感谢啊。。。所幸支付宝还能和现在的帐户绑定,毕竟我身份证只有一个。这理由真扯蛋)
4、上周五刚注册时。阿里妈妈能够登录了。好开心
5、周一,再登录。突然提示说:帐户存在异常,要我验证后才能开通
6、输入用户名密码,下一步的时候提示我,请输入手机号,还说:“1.请您放心,手机号码仅用于系统生成短信编码,不会对外泄露”,于是我输入了我的手机(绑定A的手机),结果它提示我:“此手机已绑定其他账户,无法进行验证,建议更换其他号码操作”
首先我想问的是,如果你只是用于生成短信编码,你为什么还要一个未使用过的手机?其次,我明明是采用邮箱注册的,你不用邮箱来验证,却要使用手机?
7、咨询客服。客服说无法解决,一定要我绑定手机,还要我将原来的淘宝帐号绑定的手机解绑。
这真是一个笑话。好吧,至此,如果我不能登录,相当于我毁了一个7年的阿里妈妈帐号,毁了一个新的淘宝帐号、毁了一个支付宝帐号。
虽然阿里妈妈帐号没什么钱,只是我觉得负责这两个项目,或者说让我这样验证的产品经理很2B。不管是阿里妈妈的还是淘宝的。。这种思维真有意思。
Tags: 阿里妈妈, 淘宝, 产品经理
Misc | 评论:1
| 阅读:22568
Submitted by gouki on 2014, June 5, 5:02 PM
先申明。。。参考本文,我并没有成功的搭建成功。因为我在执行第一个rpm --nodeps -ivh Runtime的时候。不是按照预想的安装在了/opt/mqm下面,而是提示我安装在/ filesystem下。所以我就没有办法下一步。因为在执行第二个安装的时候,它提示我没有在/opt/mqm下找到runtime。。。
不过我还是做个记录,因为我是debian系统。也许ubuntu下就会成功呢??原文来自:http://qtlkw.iteye.com/blog/744052
我转贴的并不全。下面的一些介绍我没有转,如果有兴趣可以移步原文,以下是转贴:
可参照文档http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=/com.ibm.mq.amq1ac.doc/lq10120_.htm 和http://blog.csdn.net/lang_ysh/archive/2010/03/18/5391971.aspx
1. Download WebSphere MQ7 tar.gz
2. run tar -zxvf CZ4VDML.tar.gz
3(optional). 创建WebSphere MQ 必需的文件系统,命令如下:
# for product code
mkdir /opt/mqm
# for working data
mkdir /var/mqm
网上看到说MQ安装时候默认的目录就是这两个
4. 创造MQ用户和用户组,命令如下:
groupadd mqm
useradd -d /var/mqm -g mqm -G mqm mqm
# change password to "password"
passwd mqm
5. 为mqm用户组添加root组
cd /etc
vi group
找到mqm:x:1003:mqm增加",root",修改成: mqm:x:1003:mqm,root
6(optional). 调整系统参数(视需要而定,我安装时并没修改)
make following kernel changes (/etc/sysctl.conf ):
kernel.msgmni = 1024
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.sem = 500 256000 250 1024
fs.file-max = 32768
net.ipv4.tcp_keepalive_time = 300
To load these sysctl values immediately, enter the command sysctl -p.
If you do not issue the sysctl -p command, the new values are loaded when the system is rebooted.
7. 安装rpm
sudo apt-get install rpm
8. 转到WebSphere MQ解压后的目录中,获得WebSphere MQ授权,命令如下:
./mqlicense.sh -text_only
阅读全文后,选择1接受授权。
9. 安装WebSphere MQ客户端和服务端,命令如下:
rpm --nodeps -ivh MQSeriesRuntime-7.0.1-0.i386.rpm
rpm --nodeps -ivh MQSeriesSDK-7.0.1-0.i386.rpm
rpm --nodeps -ivh MQSeriesJava-7.0.1-0.i386.rpm
rpm --nodeps -ivh MQSeriesClient-7.0.1-0.i386.rpm
rpm --nodeps -ivh MQSeriesSamples-7.0.1-0.i386.rpm
rpm -nodeps -ivh MQSeriesServer-7.0.1-0.i386.rpm(如果只装客户端,这个没必要安装)
原因: 不加-nodeps会报:
root@localhost:/apps# rpm -ivh MQSeriesRuntime-7.0.1-0.i386.rpm
error: Failed dependencies:
/bin/sh is needed by MQSeriesRuntime-7.0.1-0.i386
10. 安装校验
rpm -qa | grep MQSeries
MQSeriesSDK-7.0.1-0
MQSeriesClient-7.0.1-0
MQSeriesServer-7.0.1-0
MQSeriesRuntime-7.0.1-0
MQSeriesJava-7.0.1-0
MQSeriesSamples-7.0.1-0
安装MQ Explorer还需要安装其它的包:
MQSeriesConfig-7.0.1-0.i386.rpm
MQSeriesEclipseSDK33-7.0.1-0.i386.rpm
MQSeriesJRE-7.0.1-0.i386.rpm
至此MQ安装完成。
--END--
Tags: websphere
Linux | 评论:0
| 阅读:17488
Submitted by gouki on 2014, June 5, 4:58 PM
我在上一篇博客在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' ; |
5 |
'Version' => MQSERIES_MQCNO_VERSION_2, |
6 |
'Options' => MQSERIES_MQCNO_STANDARD_BINDING, |
8 |
'ChannelName' => 'CLIENT.CHANNEL' , |
9 |
'ConnectionName' => $mq_host_ip , |
10 |
'TransportType' => MQSERIES_MQXPT_TCP |
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); |
19 |
echo 'Connection good!' ; |
Obviously you’ll need to adjust the settings to fit your server, but at least this gives you a start.
--END
PHP | 评论:0
| 阅读:19802