Blog

  • Improve Magento entity setup

    Magento 文档鼓励用 entity setup (Mage_Eav_Model_Entity_Setup) 的方式去定义实体。这个类很强大,但我觉得不够灵活,因为无法用它精确控制 attribute, attribute group 和 attribute set。

    Attribute group 和 attribute set 是在两个维度分组 attribute,这样来组织 attribute 基本够用。但 setup 这个类添加 attribute 时,有不够周到的逻辑:

    如果 $attr[‘user_defined’] == 1 && empty($attr[‘group’]),那么这个 attribute 不会被添加到任何 attribute group 和 attribute set。我觉得更好的逻辑是添加到 general attribute group。

    如果 empty($attr[‘user_defined’]) && !empty($attr[‘group’]),那么 $attr[‘group’] 会被忽略,attribute 总是被添加到 general attribute group。

    没办法,已经这样啦,提供 install entities array 时,就避免进入这两种逻辑吧。

    如果我来重写 setup 类里的 addAttribute 方法,我会:

    1. 忽略 $attr[‘user_defined’] 对逻辑的影响。一个 attribute 的 user_defined 值只决定是否允许用户用 GUI 修改该 attribute。
    2. 增加对 $attr[‘attribute_set_name’] 的检查。如果 !empty($attr[‘attribute_set_name’]),则添加该 attribute 进相应的 attribute set 或 attribute sets。现有逻辑是把 attribute 一股脑地添加进所有的 attribute sets。
  • PAYG handset is not locked to network carriers

    Today, I went into Churchill Square shopping centre. To my surprise, most shops are open on the New Years Day.

    I bought a white HTC Wildfire with an O2 SIM from Phones4u, as a gift for my mother. Phones4u is doing a promotion on 4 or 5 mobiles, and Wildfire is one of them. It is priced at £129.95 with £10 airtime purchase. It claims to be half price, but actually, I find the second cheapest supplier is Tesco, price is £159.97 without airtime purchase.

    HTC Wildfire in white
    HTC Wildfire in white

    Anyway, Phones4u is the cheapest. So I go for it. Then a second surprise – I find the handset is not locked to O2 network. I google for a while, and find it is not just my luck. Pay As You Go handset purchased from independent retailer is usually unlocked.

    This saves me about £10 to buy SIM unlock code.

    I feel very happy for trying to insert an Orange SIM before paying for unlock code.

  • Dataflow profile back to work in Magento 1.5.0.0

    Magento 1.5.0.0 目前还是 alpha2 版,因为安装到第二步就有一个很明显的 bug,本来想等等再用的。

    可是 1.4.2.0 正式版 dataflow profile 跑不起来,一点 “Run Profile in Popup”,出来的 popup 就是空白。我很喜欢用外部编辑器格式化好数据,然后用 dataflow import 到 Magento 数据库。我有很多 modules 也用到 dataflow 来完成初始化,如果 dataflow 跑不起来,会给我造成很大的麻烦。

    联想到 Magento 1.5.0.0 在 release note 里说到它对 dataflow 作了改进,我想很可能修正了 1.4.2.0 带来的 bug。两害取其轻,所以我跳过 Magento 1.5.0.0 的全新安装过程,用 1.4.2.0 的数据库让 Magento 1.5.0.0 跑了起来。果然如我所料,dataflow profile 在 1.5.0.0 下工作正常。

    Dataflow profile back to work in Magento 1.5.0.0
    Dataflow profile back to work in Magento 1.5.0.0
  • SMPlayer can disable screensaver

    刚在 Fedora 14 下用 SMPlayer 看了第一场电影,发现 SMPlayer (当前版本 0.6.9)之前版本恼人的无法阻止进入屏保的 bug 不见了。很开心,电影也好看。

    Linux software 一直在进步。

  • Too early to try Magento 1.5.0.0 alpha2

    Magento 1.5.0.0 alpha2 出来了,我下载来尝鲜。可是,安装到第二步就进行不下去了。提示是:

    There was a problem proceeding with Magento installation.

    Please contact developers with error messages on this page.

    Notice: Undefined variable: params in /path/to/magento/app/code/core/Mage/Core/Block/Html/Select.php on line 142

    这挺令人失望的。

  • 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
    
  • 芳草苑升级了

    芳草苑很久没升级了,今天重新跟上 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.