作者:linux120
发布时间:December 20, 2012
分类:服务器配置
PHP异步消息通讯,编译PHP时加上–enable-sysvmsg,否则无法支持msg_get_queue函数,轻量级MQ替代品.
send.php
//创建获取消息队列
$ip = msg_get_queue(12340);
//将消息写入队列
msg_send($ip,2,”Test Message”,false,false,$err);
receive.php
$ip = msg_get_queue(12340);
//接收并处理消息队列
while(msg_receive($ip,0,$msgtype,4000,$data,false,null,$err))
echo “msgtype {$msgtype} data {$data}:{$err}n”;
对于轻量级的MQ应用来说,PHP自带的msg_get_queue函数足够了,缺点的是只能在Linux/Unix下使用。
作者:linux120
发布时间:December 18, 2012
分类:服务器配置
个别客户因地域特殊以及管理上的问题,香港Linux服务器的安全模式是打开的,fsockopen函数是关闭的,导致安装dedecms时候无法正常安装或使用,如下为解决方案:
1、打开include/common.inc.php进行编辑:$isSafeMode = @ini_get("safe_mode");改为$isSafeMode = false;报错再安装即可。
2、安全模式下,若要创建栏目新建目录等需要在dedecms系统设置里面设置好ftp账号,强制使用ftp创建目录.
作者:linux120
发布时间:December 16, 2012
分类:服务器配置
管理过cpanel的童鞋一般都在/usr/local/lib/php.ini文件中对php环境做了配置和限制,比如disable functions,当然你肯定不希望客户在public_html目录上传自己的php.ini,导致我们对环境的限制失效吧,一个简单的方法在 /usr/local/apache/conf/includes/pre_main_global.conf 中添加如下代码:
suPHP_ConfigPath /usr/local/lib/php.ini
然后使用 /scripts/restartsrv_httpd 命令重启apache后就可以了。
作者:linux120
发布时间:December 14, 2012
分类:服务器配置
默认使用Node.js开发的站点都是在3000端口下运行的,也就是说用户必须在网址中加入:3000才能访问站点,默认HTTP端口是80,因此必须监听80端口才会让网址看起来更简洁。当然,如果整个服务器只有node.js开发的一个站点,那么只需要让app.js监听80即可,但很多时候服务器上会有其他的web应用,比如php,python,ruby等,这时候就需要nginx反向代理node.js了。
配置nginx反向代理node.js只需要在配置文件中添加如下代码:
server{
listen 80;
server_name your_node_js_site.com;
location / {
proxy_pass http://localhost:3000;
}
}
重启nginx后即生效,使用nginx反向代理node.js还可以在nginx配置添加静态文件规则,同时删除node.js中app.js的app.user(express.static(__dirname+'/public'))以减少反向代理以及node.js的开销!
作者:linux120
发布时间:December 8, 2012
分类:服务器维护
应需求需要将2.7G大小的sqlite迁移为Mysql,因sqlite3与mysql个别字段类型及长度不一致,导出的sql语句不能直接导入到mysql中,需要将sqlite .dump出来的sql语句用下列程序处理后再导入到mysql中,程序为python环境。
stm.py
#! /usr/bin/env python
### A python script written for SQLite migrate to Mysql by Linux120.com
import re, fileinput, tempfile
from optparse import OptionParser
IGNOREDPREFIXES = [
'PRAGMA',
'BEGIN TRANSACTION;',
'COMMIT;',
'DELETE FROM sqlite_sequence;',
'INSERT INTO "sqlite_sequence"',
]
def _replace(line):
if any(line.startswith(prefix) for prefix in IGNOREDPREFIXES):
return
line = line.replace("INTEGER PRIMARY KEY", "INTEGER AUTO_INCREMENT PRIMARY KEY")
line = line.replace("AUTOINCREMENT", "AUTO_INCREMENT")
line = line.replace("DEFAULT 't'", "DEFAULT '1'")
line = line.replace("DEFAULT 'f'", "DEFAULT '0'")
line = line.replace(",'t'", ",'1'")
line = line.replace(",'f'", ",'0'")
return line
def _backticks(line, in_string):
"""Replace double quotes by backticks outside (multiline) strings
>>> _backticks('''INSERT INTO "table" VALUES ('"string"');''', False)
('INSERT INTO `table` VALUES (\\'"string"\\');', False)
>>> _backticks('''INSERT INTO "table" VALUES ('"Heading''', False)
('INSERT INTO `table` VALUES (\\'"Heading', True)
>>> _backticks('''* "text":http://link.com''', True)
('* "text":http://link.com', True)
>>> _backticks(" ');", True)
(" ');", False)
"""
new = ''
for c in line:
if not in_string:
if c == "'":
in_string = True
elif c == '"':
new = new + '`'
continue
elif c == "'":
in_string = False
new = new + c
return new, in_string
def _process(opts, lines):
if opts.database:
yield '''\
drop database {d};
create database {d} character set utf8;
grant all on {d}.* to {u}@'%' identified by '{p}';
use {d};\n'''.format(d=opts.database, u=opts.username, p=opts.password)
yield "SET sql_mode='NO_BACKSLASH_ESCAPES';\n"
in_string = False
for line in lines:
if not in_string:
line = _replace(line)
if line is None:
continue
line, in_string = _backticks(line, in_string)
yield line
def _removeNewline(line, in_string):
new = ''
for c in line:
if not in_string:
if c == "'":
in_string = True
elif c == "'":
in_string = False
elif in_string:
if c == "\n":
new = new + 'Newline333'
continue
if c == "\r":
new = new + 'carriagereturn333'
continue
new = new + c
return new, in_string
def _replaceNewline(lines):
for line in lines:
line = line.replace("Newline333", "\n")
line = line.replace("carriagereturn333", "\r")
yield line
def _Newline(lines):
in_string = False
for line in lines:
if line is None:
continue
line, in_string = _removeNewline(line, in_string)
yield line
def main():
op = OptionParser()
op.add_option('-d', '--database')
op.add_option('-u', '--username')
op.add_option('-p', '--password')
opts, args = op.parse_args()
lines = (l for l in fileinput.input(args))
lines = (l for l in _Newline(lines))
f = tempfile.TemporaryFile()
for line in lines:
f.write(line)
f.seek(0)
lines = (l for l in f.readlines())
f.close()
lines = (l for l in _process(opts, lines))
for line in _replaceNewline(lines):
print line,
if __name__ == "__main__":
main()