weblog me >> weblog.areverie.org

周末折腾PHP的几个事情

这周六公司搞了一个所谓的”技术交流大会”,呃,其实说白了就是阶段性地展示一下成果,拿出来和大家了解了解。我这边比较惭愧没啥系统架构上可以谈的,于是就扯了一个Vim的推广slide (下周整理完了准备贴出来)。

结果是周末就只剩今天一天,我也懒得继续填BoP的坑,调教完Emacs前,暂时拿Sublime Text 2来凑合一下——要知道用Vim来做翻译实在太坑爹了,几个模式来回切换还要切换输入法总是搞的手忙脚乱,某也尝试过easy vim,不过还是未果——始终用不惯鼠标。

商务把刚刚出了点问题的单车去修理了一下,中午吃了个饭后静下心来也没心思推gal或者看片,于是索性望了望某那个冗长的to-do list——久违地折腾一下吧——结果是搞到现在囧。

PHP 5.4 在Lion上编译

1
2
3
4
5
6
7
8
9
10
11
12
Undefined symbols for architecture x86_64:
  "_rl_on_new_line", referenced from:
      _zif_readline_on_new_line in readline.o
  "_history_list", referenced from:
      _zif_readline_list_history in readline.o
  "_rl_mark", referenced from:
      _zif_readline_info in readline.o
  "_rl_pending_input", referenced from:
      _zif_readline_info in readline.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1

今天打算把mac姬的php升级到5.4.0尝试一下,结果make的时候报了如上错,以为又是brew里带的readline有问题,检查了$CFLAGS等等环境变量后又换了自己编译的readline还是没用,于是怀疑是林檎的llvmm-gcc有问题(xcode的autotools?);再尝试了gcc-4.2后还是无果。于是又求助大G,最后找到了相关信息,解决方法比较…无语,把gcc的include path顺序换一下就好了。具体方法如下

  • 执行./configue,生成Makefile
  • 修改Makefile,在某的情况下是第146行,把$(MH_BUNDLE_FLAGS)移动到最后去。
1
2
3
4
# 把
$(CC) $(MH_BUNDLE_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@ && cp $@ libs/libphp$(PHP_MAJOR_VERSION).so
# 改成
$(CC) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) $(MH_BUNDLE_FLAGS) -o $@ && cp $@ libs/libphp$(PHP_MAJOR_VERSION).so
  • 继续make就解决了

另外,每次升级php在mac姬上都比较麻烦,而且环境隔离比较累,例如extension、配置文件、启动bin等等。虽然之前有过和rvmpythonbrewperlbrew一样的phpbrew,不过在某的情况里不太适用,近期打算自己写一个。

查询PHP文档太麻烦

这个问题相信不是PHP的问题…每种语言、每个程序猿都有这个问题,而对于某来说,在CLI下还得挪到浏览器里搜索是件很不情愿的事情。于是想起了pman这个东西,使用起来非常方便。

pear install doc.php.net/pman

然后和man一样

pman strlen

pman in terminal

在vim里可以调用

!pman foo

甚至可以设置后,使用K来快速查看cursor所在keyword的文档,只需要在vimrc里加入

autocmd FileType php setlocal keywordprg=pman

不过话说回来…在某这里按q退出后vim会提示结束还得按下enter才能回到vim界面,而且如果想查更详细的文档还是得打开php.net来查。受到这篇文章的启发,打算把php.net的爬下来自己做一个镜像来做文档查询功能,速度快,也有模糊匹配。具体做法官网已经给出了具体做法。我就直接说说我的做法吧

  • 用rsync把需要的文件给爬下来…这个取决于你的网速了,只需要文档的话可以参考如下命令
1
2
3
4
5
6
7
8
# 如果需要其他语言的文档可以一起rsync,例如中文的在 manual/zh下
rsync -avzC --timeout=600 --delete --delete-after \
--include='manual/en/' --include='manual/en/**' \
--exclude='manual/**' \
--exclude='distributions/**' \
--exclude='distributions/manual/**' \
--exclude='extra/**' \
rsync.php.net::phpweb /your/local/path
  • 这样的文件总大小大约在1GiB左右,不过文件比较多,耐心等待一下吧
  • 拉下来的网站文件本身都是php的,所以我们需要一个php的服务器环境,并且最好能支持sqlite3扩展(这个有关搜索功能)
  • 按照官方给的建议设置apache(我也懒得折腾nginx了)
  • 不过URL跳转似乎有点小问题,我又懒得折腾所以用nginx转发过去了,设置可以参考下面:
1
2
3
4
5
6
7
8
9
server {
  listen 80;
  server_name foo.bar;

  location / {
    proxy_pass http://your_server_ip:port;
    proxy_set_header Host php.dev.areverie.org;
  }
}
  • 跑起来,访问一下如果一切正常的话,就和php.net官方一样啦。实际上那些镜像也就是这么做的(ry

当然这还不是全部,还可以在Chromium酱的搜索引擎里设置一下,添加一个php文档,URL可以是http://foo.bar/manual-lookup.php?pattern=%s,这样是不是就更加好玩实用了呢XDD

search local php.net mirror

PHP 5.2和5.3还有5.4到底有啥区别…

其实某真的没认真了解过,借口是其实某也没多了解php,懂点皮毛而已,不过大概的概念是有的。官方给了一篇迁移的说明,还是打算认真看看;当然也不能少了升级到5.4的说明

可以看到5.4后php也有向ruby、python、javascript等语言学习的地方…最近因为听到不少人发表了

PHP就是码农的语言

这样的言论。

对自己熟知的工具、事物被说这样的话总有点心理抵触,不过再深入理解他们的论据后确实有一定的道理,多学习和借鉴先进生产方式的思想总是有一定益处的。说白了还得提高自己的档次啊XDD

Wikipedia 2012 Spring Meetup in Shanghai

今天是维基百科上海春聚活动,我和AddisWang、上海工部局、Mountain约好下午在徐汇软件基地,和kegns碰头。聚会的具体活动页面可以参考这里

很高兴的是TEDxChina的参与者之一的王先生也到场和我们分享TED知识传播的经验分享,就前几次聚会来说,上海的聚会一直有点问题,主要体现在以下几点

  • 宣传不足(知名度不足)
  • 分享的内容比较单一、重复
  • 组织比较混乱

这些问题对一个立足于线上的社群来说是致命的,搞线下聚会的目的也是能够结识更多兴趣相投、能够共同发展的伙伴,交流知识经验寻找更大的发展机会。当然,因为众所周知的原因,维基百科在大陆境内是无法成立基金会组织,也就没有正式的宣传动力来做到一个NGO那样性质、规模的活动。 会后小聚上,再加上JuneAugust、活动场地的提供方环球教育的高先生(十分感谢)探讨交流了一些线下活动的经验、不足。 TED的王先生很鲜明地指出我们对线下活动准备不够充分,TED主要是立足于线下聚会,近年来才更关注线上资源的一个社群。给了我们不少意见,当然某个人在几次活动也感觉到有些问题。

接下来的工作给我们上海的维基编辑、活动的组织者来有一个比较重的课题,Mountain最近打算回北京发展,AddisWang在夏季后会出国留学,得从长计划一下上海维基百科社群的发展,维系工作。

我们还能再加以改进的一些方法,某想有

  • 更有针对性的社会化媒体宣传
  • 大力发展学生群体的积极性(这些人群是最有精力、热情的群体)
  • 学习台湾的双周会制的,有针对性的老手带新手活动
  • 聚会时、聚会后的反馈和改进

可能由于我们这里组织活动的人都比较年轻,缺乏经验,加上本身搞技术出身较多,不善于灵活开展社区活动,所以接下来的活动中,某打算和其他城市、或者同类型的社群讨教讨教经验,想办法把上海维基百科社群发展下去。

我们目前还比较缺乏的资源主要是每次活动的场地,报名人数一次比一次多,由于场地和经费(原则上我们尽力不收取任何费用)的限制,使得聚会活动质量无法保证。

留给我们的还有更多的要去做。但某还是有信心的。

Migrate to Octopress

前段时间见识了Jekyll的强大转换,后来知晓了octopress这个号称给hacker用的blogging框架;再仔细看了一下之后发现,这东西正是我梦寐以求的blog发布模式

  • 使用git或者rsync来push发布
  • 远程服务器甚至不需要任何语言的运行环境,只需要一个webserver
  • 可以使用markdown作为本文标记
  • 还有机会玩玩ruby
  • 只提供最基本的功能
  • 界面可以随意定制(直接空手写代码即可)

于是在公司的内部记录日志上尝试了一下之后对octopress非常满意,周末趁有空在github上发现了一个用来把wordpress的文章导出来转换成markdown的项目。除开一些小小的问题,例如转换utf8、图片链接得重新替换外(某觉得这应该难不倒想成为”hacker”的各位XDD),基本无障碍地切换到octopress上来了。

然后某选择了台湾的@tommy351所制作的slash主题,简洁舒畅。

接下来留给我的一些想法是:

  • 继续熟悉markdown的语法,发现有些语法在写代码的文档时用不到,但写blog就用到了
  • 有空再定制一下界面
  • 继续玩ruby的过程中多折腾折腾,自己也搞一个主题出来

P.S. 顺带,hacker们还真喜欢章鱼这种生物啊XDDDDD

Build NINJA-IDE on Mac OS X Lion From Source

Though I’m mainly using VIM as my full-functionality editor for daily works. Sometime I just want to try something else. Somewhat like ar… A Integrated Development Environment?

I have to admit Eclipse is a great IDE for developing Java / PHP (you use cracked Zend Studio?) and with a plugin called Aptana we can also write Ruby / Python stuff with it. But I don’t like java much.

So that’s why a IDE for Python called NINJA-IDE caught my eyes, especially itself written in Python. We can find it here and here. NINJA-IDE is built from python and Qt for GUI. so make sure you have PyQt (at least version 4) runtime on your system.

If you are using the python within homebrew, you can just open terminal.app and key the following command and waiting for things’ done :)

brew install -v sip
brew install -v pyqt

For me, I’m using Mac OS X Lion so I choose not to screw the native python environment up. You can use pythonbrew.

And one thing must be pay attention. Sip and PyQt4 don’t use the standard setuptools to install. We have to download the latest source code and build ourself. They also require python to be built in framework mode. If you are running on Linux or not the same as me, I suggest you refer to your system’s manual or google for about how to build these things.

So let’s get started :)

all the stuff we will need can be found as:

First, make sure the python has been built for framework mode.

# is supposed to be something like:
/Users/aleiphoenix/.pythonbrew/pythons/Python-2.7.2/Frameworks/Python.framework/Versions/2.7/bin/python

about how to build python for Macosx/Darwin framework

# use pythonbrew
# add `--framework`
# `--universal` for build 32bit / 64 bit for intel CPUs
# `-n` for
pythonbrew install --framework --universal -n 2.7.2

building Sip and PyQt4 is similar

# cd into source folder
# `-n` for universal binary
python configure.py --arch=x86_64 -n

# then `make` and `make install`
make && make install

# building PyQt4 is identical

Check whether the installation is successful. If don’t get any error, congratulations!

python -c 'import sip'
python -c 'import PyQt4'

Now we can start NINJA-IDE by hitting for following command in source code folder.

python ninja-ide.py

OK… the interface is not so awesome as their website.. but guess I will have a try with it :D

Planning a New Php Framework

A framework widely used in my workplace call APF V2 is very powerful I have to admit. But some design of it just slow down the development, and sometime I won’t use those libs. I find myself not really familiar with PHP and web developing or I’m just a web developer, coding for food. But after all I want to be a designer of my code and work.

So after some tries I will plan to write a lightweight framework for my daily php developing. Also it will help me understand more details about how to make code together to work and the language itself. I am learning python and going to learn RoR so guess i will take advantage of  some ideas from them :)

The framework is aiming for fast developing, basically MVC design mode, restful and stick with standards(HTML/HTTP i mean), make coding more simple and easy.

I’ve created a repository on github. So if you’re interested in this new work, you can join me. Just drop a piece of comment here.

Enable Font Smoothing for Mac OS X

OK, Mac OS X looks good enough for me… but wait…

When I change to some kind of external display such as my Dell U2410, the font smoothing of terminal fonts went disappeared! WTF…

I’ve check the font smoothing settings in the ‘perference => general’, it’s been checked. So I googled for a workaround. Here it is.

defaults -currentHost write -globalDomain AppleFontSmoothing 2

The number 2 means always enable font smoothing here. So that’s it!

My terminal’s looking good once again :)

font smoothing comparing before and after enable

Trac升级后注册时遇到的报错解决

前阵子公司里的一台办公室server升级,迁移重启后trac启不来了,不停报错。当时电话通知我解决,想也没想直接pip uninstall && pip install trac了一下。没注意老的版本升级成0.12.2了。 在数据库以外的问题,就是注册时总是提示。

AttributeError: 'AccountChangeNotification' object has no attribute 'smtp_server'

在mod_python的httpd下error_log竟然看不到错误。动手把trac.ini配置里错误输出到指定文件后发现traceback大意是acct_mgr下notification.py的146行有报错。没有smtp_server属性。由于该行代码是trac自身记录日志用的,不影响使用。可以直接注释掉。 另外由于安装TracAccountManager时用的是蛇蛋,所以需要把notification.pyc文件删除后重启httpd才能生效哦。

这个故事告诉我们。。在没法debug的情况下(大部分情况),traceback是很重要的。嗯嗯。

Php Compatibility With Phpredis

I’ve been playing around with redis recently.

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

…Um, that’s from the official site. Actually I just use it as a key/value data store and some kind of message queue. I chose it because the language binding’s wide spread but not so as the PHP. I’ve googled for several benchmark of the php extension, finally looking into phpredis (not the php-redis). I encountered the compatibility problem with it today. The fix is easy and fast. (you could find it here). But my question is…

why doesn’t the compiler throw out a error when processing the undefined macro?

wondering… i’ll figure it out later…

PC机删除grub的一连串悲剧

一晃眼已经在十一长假了,最近某一直在热衷于写wiki;不仅仅是zh.wikipedia.org,还包括en和ja以及……各种折腾东西的wiki,当然还有某自己的wiki.areverie.org。最近某喜欢听故事,也喜欢讲故事。今天就给大家讲个故事吧。

突然会发这么一篇网志是因为……最近在PC上的折腾差点要了某半条命。先是从玩了gentoo后,打算把不需要的linux都删除,这就意味着某打算把原本家里的PC上的archlinux和grub删除。这一删不要紧……要命的是后面一连串的故事。

首先我知道删除grub会影响MBR,导致无法启动windows,于是某上网查询了一番。找到了一篇关于安全删除grub的办法,太过复杂所以PASS……于是某果断寻求删除linux分区后重建windows的MBR(刚开始某还不知道应该是Win7的)。于是很顺利地在磁盘管理程序里把linux的分区删除了。重启果然启动不了,于是上网开始查如何修复…… 尝试了几个XP的解决方案不行后,找到一篇重建windows bootmgr MBR的文章很不错,按照这个方法在安装光盘进入安装界面后按shift+c即可启动cmd,随之而来确认分区,重建bootmgr很顺利。系统也正常启动。于是某也就没在意了……

戏剧性地是……玩mabi的时候在做G12的BOSS,顺手录了一下视频,C盘一下就告急了(吃了9个GB呢),并且专门放实用工具和镜像的分区50GB也快满了。于是打算把删除掉的linux分区多出来的100GB利用起来。不做还好,一尝试,在磁盘管理器里提示没有足够空间完成操作。刚开始以为是C盘临时空间不足,才去清理视频,之后才意识到思路完全不对——这和C盘临时空间没任何关系。网上查了一下说是磁盘分区表的间隔有问题(的确linux和windows在处理逻辑分区上有点区别),最后找到的方法都是转换为动态盘,不过这可不现实,因为某的主要硬盘还有OS在,所以稀里糊涂地看文章以为用分区工具重新修复一下能解决问题……这才是噩梦的开始。

某把N年前的XP光盘翻了出来(还是深X的),光驱启动……哦这里不得不提一下,在上个月某的第3台DVD刻录光驱光荣退役——战死,虽然某都没怎么让它战……所以翻箱倒柜把5年前刚买PC那会儿那个DVD-ROM驱动器挖出来,一试果然还能用。点亮毫不犹疑地进了PQ魔术分区,迎面而来就是警告提示分区有误,是否修复,点了几个dialog之后,我已经不耐烦地狂点鼠标左键了——这才是最失败的地方;一进PQ主界面,看到的就是一块硬盘分区的图示——提示失败……这下我背后冒冷汗了,不会出什么问题吧,赶紧exit掉尝试boot系统……

在多次连续boot过程中重启已经宣判了我的硬盘上的7娘的死刑……缓期。于是某又想都不想,打算从PE环境中尝试修复——无果,还试图花了6个小时的时间找各种版本的PE,刻盘、写入闪盘,尝试从外置硬盘和LAN去备份数据——索性外置硬盘和机箱内另外一块硬盘没有问题。困扰我这么长时间不因为别的,只因为在PE2.0里,某能看到正常的分区,还能读写数据!最后我把外置硬盘和机箱内第二块硬盘拿下来插到mbp上发现没问题时,某才意识到可能是……分区表MFT的问题?

google又在危难时刻救了某,简单地把分区shrink一下就解决问题了……unmount硬盘,断电,重新插上后一切正常orz

事实就是这么残酷,真正解决问题花的时间才那么几分钟,过程中却要折腾……呃,将近8个小时。还好数据没任何损失,正在我执笔的时候,把硬盘拆下来,放在底座上正在备份数据。

这个故事告诉我们……

备份很重要,不做的话出问题哭也来不及哦XDDDDDDDDDDDDDDDDDDDDDDDDDDDD

其实真正想说的是,做事情还是不能太想当然,任何问题都要先分析清楚,不做没把握的选择。

Macbook Pro

Yep, at last I’ve got myself a ‘2011 macbook pro 15 (actually 8.1?) .

After a week play around with her, I have to say it will never be a bad choice I’ve ever made. I should have purchased a macbook nearly 2 years ago, but I chosen dell studio 1557 (with Intel i7 quad core processor and AMD HD4570 graphic card, of course 4GB RAM ) because I’m not so sure I could just say goodbye to windows. Thanks to dell, that laptop bring me into the world of linux and unix, shown me even a wonder-er landscape of computer and system. :) The fancy famous touchpad now is my best friend. I can just focus on keyboard with vim(when coding and ssh) ,vimperator(browsing the Internet) and never think about the mouse. :D Since I’m not a heavy compiling language developer so the basic php/python and unix(actually BSD) environment is good to me. Although the most of OS X already meets my needs, I still plan to intsall gentoo prefix (already done :D) and upgrade the RAM to 8GB. I was purchasing this mac just one day before Lion going released, So I need to apply for upgrade plan while I’m looking forward to it. Now I’m enjoying time with mac :D

Here’s some photos.

[gallery link=”file” columns=”3” orderby=”ID”]