Category: 小小草

IT 技术领域学海无涯。其实任何领域都学海无涯,无非 IT 发展太快了,让我有更多嘘唏。希望我掌握的技术有如小小草,虽然渺小,却有旺盛的生命力。

  • I am leaving Zend Server

    Creating domain error after installing Zend Server
    Creating domain error after installing Zend Server

    I used to deem Zend Server is overall a good solution for php website development and deployment. However, over a year’s time I realise it brings so many troubles. It is not compatible with Plesk as shown in the screenshot. I can not solve this problem.

    It stops yum on Fedora. I can solve this problem but, troublesome.

    Do I enjoy any unique feature of Zend Server? None as I can remember. Occasionally I use “debug on server”, but it is a feature of Zend Debug, not of Zend Server.

    Also, Zend Server pulls me back to Apache, to which I prefer Nginx.

    Actually, I have no reasons to love Zend Server. So I decide to leave it.

  • Solve Google Desktop 64bit indexing few files

    Google Desktop Index Status
    Google Desktop Index Status

    我的电脑上只有 19 个文件?这怎么可能!

    Google Desktop 64bit 在 Fedora 11 上不能正常建立索引,在 Fedora 14 上仍然不能,我很是失望。我用 Fedora 11 时尝试找别人是怎么解决这个问题的,没找到,最后不了了之。现在用 Fedora 14,重新找了一遍,找到一个:

    ln -s /opt/google/desktop/lib /usr/lib64/tls/x86_64
    

    原因嘛,据说是 /opt/google/desktop/lib/libgdl.so 没有放在正确的位置。更具体的原因嘛,我也说不上来了。

  • Fedora 11 freeze at login screen

    圣诞啦,收拾房子,发现两张纸的零碎笔记,是关于如何解决 Fedora 11 安装到尾声,因某些显卡驱动程序有 bug, 花屏死在图形界面。

    当时没有整理到芳草苑发表,时间一长就忘了。Fedora 发展到了 14,可能这个 bug 已经不复存在。我也忘了具体显卡型号,反正是一台很老旧的机器,intel 的集成显卡,当时想装 Fedora 11 让它重焕青春,我花了很长时间解决这个问题,现在简单说说吧。

    1. 要在机器花屏停止响应之前,按 Ctrl + Alt + F2,进入 terminal,输入用户名、密码,然后输入

    init 3
    

    2. 然后输入

    yum install system-config-display
    

    有时会有 “Could not retrieve mirrorlist” 的错误,多试几次就可以

    3. 然后输入

    system-config-display --noui
    

    这条命令生成文件 /etc/X11/xorg.conf

    4. 在 /etc/X11/xorg.conf 里添加一行
    Option “NoAccel” “true”
    具体位置我忘了。

    5. 然后输入

    init 5
    

    即可进入图形界面。不过 NoAccel 关闭了硬件加速,如能安装正确的驱动当然更好,据说以下命令可以,不过我没试过。

    rpm -Uvh --oldpackage http://mirrors.kernel.org/fedora/updates/9/i386.newkey/xorg-x11-drv-i810-2.3.2-3.fc9.i386.rpm
    
  • Magento page speed benchmark

    There are some website benchmark tools, looking after various aspects of performance.

    The tool I use most is Apache Benchmark, and parameters are 10 concurrencies, e.g.

    ab -c 10 -n 200 (page_url)
    

    It reflects the status quo. I have a decent server but the sites are not busy.

    Since I dived into Magento, I have been spent quite a lot researching how to improve its speed. I implemented database query cache, enabled block html cache, utilised memcache, tmpfs, apc, etc, etc. Recently I started a project called Full Page Cache Preparer (FPCP) and expected it fundamentally improve Magento speed on Catalog and Cms pages.

    FPCP is only 20% completion (it is not producing all blocks with session variables, but shopping cart sidebar), but I am eager to see some result. So I turn it on and compare the Requests Per Second to the time when it is off. I see a marginal 1-2% improvement which is very disappointing.

    Why I had the impression that full page cache feature will dramatically drive Magento faster? What if full page cache is working with web server cache, say nginx ncache? I simulate a test by saving a page html source code to a static file and uploading it to web server. (I should have done this test before I started FPCP project.) The result is disappointing, again.

    The test is done on a heavy page (with loads of images).

      ADSL connection (8,187/1,291 kbps) to datacentre 100 mbps ADSL connection (4,212/1,078 kbps) to datacentre 100 mbps directly run ab test on webserver
    Request via Magento /index.php 9.18 4.56 16.23
    Request a static .html file on filesystem (bypass php parser) 8.23 4.65 3368.82
    Request a .php file on filesystem (same content as .html, no php tag inside) 8.72 4.62 1584.05

    The figures in first two columns (ADSL connection) go up and down when I run tests again and again. Sometimes requesting a static file is even slower than requesting Magento index.php. My conclusion is, even when Magento full page cache is working in conjunction with nginx ncache, I cannot feel the sites are faster (when the server load is not high).

    However, I will finish my FPCP module (some day) because I believe it benefits people whose server load is high. To improve my own sites, I will focus on basic (if I call FPCP hi-tech) page speed recommendations, e.g., optimise images, concurrent downloads, cookieless domains for static files, merge js/css files, gzip, etc.

  • Save comma separated csv files in OpenOffice

    I want to establish a protocol for my dataflow in Magento, part of which is “all csv files contains import data should be comma separated”.

    OpenOffice is an efficient tool to edit csv files, but how to save them using comma separator? I found OpenOffice behaviour quite unpredictable, sometimes comma separated, sometimes semi-colon separated. Maybe it depends on csv original format upon opening or creating.

    How to always save a comma separated csv in OpenOffice?

    I did not find a way to make it happen by default, but it can be achieved by 2 steps:

    1. Use “Save As…”, and check option “Edit filter settings”

    Check Edit filter settings
    Check Edit filter settings

    2. Set comma as Field delimiter

    Filter settings dialogue
    Filter settings dialogue
  • Magento helper class is a singleton desin pattern

    Magento did not mention this (or hide somewhere I could not find), so I’d like to mention it:

    Magento helper class is a singleton desin pattern. Whether a helper class is called in a format as

    Mage::helper('mymodule')->helperMethod();
    

    or as (in a block class or a template),

    $this->helper('mymodule')->helperMethod();
    

    the helper class is only initialised once.

    Which means Magento puts a singleton desin pattern on helpers.

  • Solving “Fatal Python error” after installing Zend Server

    我想这是个普遍问题:在 Fedora 14 里安装了 Zend Server 以后,yum 不工作了。比如 yum update 错误提示:

    Fatal Python error: pycurl: libcurl link-time version is older than compile-time version

    幸好有 google 和 Fodera forum,找到一堆建议,先试了一个不管用的(python-pycurl, libcurl 两个 packages 我还是专门找了最新的版本,依然不管用)

    rpm -Uvh --force http://mirror.bytemark.co.uk/fedora/linux/releases/14/Everything/x86_64/os/Packages/python-pycurl-7.19.0-7.fc14.x86_64.rpm http://mirror.bytemark.co.uk/fedora/linux/updates/14/x86_64/libcurl-7.21.0-6.fc14.x86_64.rpm
    

    又试了一下这个管用:
    1. 先把 Zend 库改个名

    mv /usr/local/zend/lib /usr/local/zend/zendlib
    

    2. 用 OS 原有的库替换 Zend 库

    ln -s /usr/lib64 /usr/local/zend/lib
    

    这时 yum 正常了,但 apache 起不来了。

    3. 软链接 Zend apache2 在原位置

    ln -s /usr/local/zend/zendlib/apache2 /usr/local/zend/lib/apache2
    

    apache 正常了,但是 Zend Server web interface 里大量的错误,因为只连了 apache2,还有一大堆跟 Zend Server 相关的文件没连。是继续一个个连呢,还是?

    以下是我自己的做法:
    推倒前述 1,2, 3 步重来。
    1. 把该死的随 Zend Server 来的 libcurl.so.4 删掉或改名

    mv /usr/local/zend/lib/libcurl.so.4 /usr/local/zend/lib/libcurl.so.4.bak
    

    这下 yum, httpd, zend server web interface 都正常。既然是 /usr/local/zend/lib/libcurl.so.4 导致 yum 有问题,删了不就行了,就这么简单。

  • Install HP printer in Fedora 14

    First printout in Fedora 14
    First printout in Fedora 14
    今天终于把 HP LaserJet 1010 装在了 Fedora 14 上。

    我从 Fedora 11 升级到 Feora 14 已有几周,但一直无法在 Fedora 14 下使用 HP LaserJet 1010 打印机。期间我一有空就想解决这个问题,直到今天才成功,好累。想当初在 Fedora 11 上安装这台打印机很顺利,我估计根本原因是 HP 驱动在 Fedora 14 上多少有点问题。回溯几个迂回的片段:

    首先从 HP Linux imaging and printing 的网站上下载了 hplib 3.10.9,运行其中的 hplip-3.10.9.run,被提示没有 gcc。我用

    yum install gcc gcc-devel
    

    仍说没有 gcc。我只好再试

    yum install gcc-c++
    
    HPLIP missing gcc
    HPLIP missing gcc

    这下 gcc 这一关过去了,但仍缺少一堆依赖包,为了求简单,我没有细究我的系统是否需要,按 google 来的建议一股脑地装了很多 packages。

    yum install cups libjpeg-turbo libjpeg-turbo-devel openssl-devel net-snmp-devel libusb-devel python-devel xsane sane-backends-devel dbus-devel libtool
    

    这下 hplip-3.10.9.run 似乎成功运行完毕,在系统托盘上添加了 HP Device Manager 图标,也能看到 HP LaserJet 1010 打印机列在其中,但一打印,提示 cups-missing-filter。这种错误提示实在不知所云。想在 HP Device Manager 删了打印机再重装,竟然不让删。

    有人说这是 system-config-printer 有问题,只有 cups web interface (http://localhost:631) 才正常。

    我在 cups web interface 尝试去删除打印机,果然成功!得,以后就用 cups web interface 去管理打印机。但是,重装打印机并没有解决问题,一有打印任务就提示 cups-missing-filter。我在 cups web interface 里看到一个新的线索:找不到 /usr/lib/cups/filter/foomatic-rip-hplip。这大概是 cups-missing-filter 所谓的 missing filter 了。

    我从 hplip-3.10.9.run 的安装目录/prnt/hpijs/ 里找到 foomatic-rip-hplip,拷贝到 /usr/lib/cups/filter/,这时打印不再提示 cups-missing-filter,但仍无法打印,在打印任务栏看到所有 print job 都是一打印 status 就成 stopped。

    我没有继续以下尝试,而用重编译 hplib 的办法解决了问题。如果再来一遍,我会尝试

    chmod 755 /usr/lib/cups/filter/foomatic-rip-hplip
    

    因为我后来看到 /usr/lib/cups/filter/ 下的文件都是 755 属性。

    重编译 hplib 是我在 Fedora 14 下安装 HP LaserJet 1010 打印机最精彩的部分,因为:
    它是最终解决方案;
    我不懂编译原理,只会依样画瓢,然后看到一大堆字符在终端里滚动,神秘的东西总是精彩的;
    我曾想绕过问题在 Fedora 14 下安装另一台 HP LaserJet 1020 打印机,也未成功,说明 HP printer drivers 在 Fedora 14 普遍有问题,那么解决方案也是有普遍适用性。

    言归正传。重编译 hplib 之前要先 uninstall hplib。

    1. 以 root 身份进入 hplib 的安装目录

    su -
    
    cd /path/to/hplip-3.10.9
    

    2. 依次执行

    make uninstall
    
    rm /usr/share/hplip -rf
    
    rm /etc/hp -rf
    
    rm ~/.hplip -rf
    
    rm /var/lib/hp -rf
    

    很多的 rm -rf 哟,小心输入。

    现在开始重编译 hplib。

    3. 依次执行

    make clean
    
    ./configure --prefix=/usr --enable-qt4 --enable-doc-build --disable-cups-ppd-install --disable-foomatic-drv-install --enable-foomatic-ppd-install --enable-hpijs-install --disable-policykit --disable-cups-drv-install --disable-hpcups-install --enable-network-build --enable-dbus-build --enable-scan-build --disable-fax-build --disable-foomatic-rip-install --enable-foomatic-rip-hplip-install
    
    make
    
    make install
    

    在执行 ./configure 时会有一些 warning,大意是跟 foomatic 相关的 options not available。估计有些配置对 hplib 早期版本适用,而对 hplib 3.10.9 无效。Anyway, 这也能完成编译,编译后安装 HP LaserJet 1010 打印机就能打印了。我也想过偷懒,在 uninstall hplib 后不想重编译 hplib,直接在 cups web interface 里添加 HP LaserJet 1010 打印机,指望 cups 能认识一些主流打印机,但没有成功。

    花费了这么多时间才安装一台打印机,我认为问题的源头最有可能是 hplip-3.10.9.run has some defects。如果再来一遍,我不再

    sh hplip-3.10.9.run
    

    而直接使用它解压出的文件。

  • I decide to follow html5 from now

    关于 html5 的消息时有耳闻,今天看到的 contenteditable 属性让我兴奋不已,所以我决定开始关注 html5。

    看看,有了 contenteditable = “true”,以后接受用户输入有了更灵活的方式。

    本文就是 contenteditable。

  • yum install php-5.3-curl-zend-server

    我快被 zend server 搞疯了。不过说到底是我自己不好——新装了一台 Fedora 14,添了 zend.repo 以后忘了运行

    yum install zend-server-ce-php-5.3
    

    过了几天开始用它来调试 Magento。貌似 zend server php 替换了原有的 fedora php,因为 php.ini 是来自 /usr/local/zend/etc。这给我很大程度上一个误导,以为 zend server 已经装好了。

    结果 Magento 跑不起来,第一个错误是没有 pdo,我略有纳闷,zend server 怎么不代我完成 pdo 安装?不过没细想,用

    yum install php-pdo-mysql
    

    解决问题。(不过回想起来,也没搞清楚这到底装了哪个版本的 pdo)

    随后发现进不了后台,第二个错误是没有 curl,这下折腾了两个小时,用

    yum install php-curl
    

    说已安装(fedora 把 php-curl 包含在 php-common)。然后我用

    yum reinstall php-curl
    

    当然无济于事。试遍各种可能的命令都不成功,两小时后发觉 zend server 没装过,于是一装 zend server,顺利启动 Magento。

    最后说一下,如果非要单独装 zend server 版的 php curl,可以用

    yum install php-5.3-curl-zend-server