Author: 芳草苑主

  • 芳草苑升级了

    芳草苑很久没升级了,今天重新跟上 WordPress 主节奏,更新到 version 3.0.3。

    这次更新的主要原因是默认主题 twentyten 很有 html5 的味道;拖了这么久才更新是当初想把当时的 default theme 改为流式布局的任务一直没完成。如今改进 default theme 已无大意义,就彻底放弃此念头。

    其实升级也很快,静下心来整一整也就三个小时,含本地测试一次。

    老版本最后一个 Google 页面预览照
  • 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
    
  • Mage_Adminhtml_Controller_action

    今天发现,我的所有的 admin controller 都写成了 extends Mage_Adminhtml_Controller_action。虽然不影响使用,我还是想把它改规范的驼峰式 Mage_Adminhtml_Controller_Action。

    于是搜索了整个硬盘到底哪些文件里包含 Mage_Adminhtml_Controller_action,结果发现这个笔误还不少。而且不光我写的 modules 里有,Aheadworks, J2t, Plieninger 的代码里也有,最后发现源头是 koukou1985 的 Magento module creator。

    看来 Magento module creator 流传甚广。

  • Magento attribute’s attribute frontend_class

    Magento EAV framework is very promising, but not easy to understand. When the code is mixed with typos, it becomes even more confusing.

    Mage_Catalog_Model_Resource_Eav_Mysql4_Setup provides a template for setting up an attribute.

    'name' => array(
    'type'              => 'varchar',
    'backend'           => '',
    'frontend'          => '',
    'label'             => 'Name',
    'input'             => 'text',
    'class'             => '',
    'source'            => '',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => true,
    'user_defined'      => false,
    'default'           => '',
    'searchable'        => false,
    'filterable'        => false,
    'comparable'        => false,
    'visible_on_front'  => false,
    'unique'            => false,
    )
    

    However, ‘class’ is wrong. It should be ‘frontend_class’. It refers to DOM class attribute assigned to this entity attribute output html. It can be used for value validation before submission. The possible classes can be found in js/prototype/validation.js. But frontend_class can be set anything you like for css styling or other purposes.