Category: 小小草

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

  • Solution to php fastcgi crashes

    One of my servers is running Fedora + Nginx + php-cgi (spawned). I noticed sometimes php-cgi crashes without a reason or warning (Nginx gives out 500 error), and I have to spawn it again.

    After some digging, I find exporting PHP_FCGI_MAX_REQUESTS to ENV cures the problem. As advised, I export PHP_FCGI_CHILDREN as well.

    To achieve that, in detail, just add the following to the top of spawn bash script.

    # Set these two env variables to reduce php-cgi crash
    PHP_FCGI_MAX_REQUESTS=1000
    export PHP_FCGI_MAX_REQUESTS
    PHP_FCGI_CHILDREN=5
    export PHP_FCGI_CHILDREN

  • Upgrade VirtualBox to 3.1.x

    刚从国内回来,电脑上积累了很多更新。其中 VirtualBox 有了 3.1.2 r56127,我从 3.0.x 直接升级失败,抛出一大堆的文件冲突信息。

    于是
    yum remove VirtualBox -y
    然后再
    yum localinstall -y --nogpgcheck VirtualBox-3.1-3.1.2_56127_fedora11-1.x86_64.rpm
    成功!

    此删除和重安装操作无须备份和恢复原有的 guest OS(but as a good practice, you should backup files before major changes)。

  • Expires affects Firefox

    我把 Magento 网店从 A 服务器迁移到 B 服务器后,发现一个问题:在 Firefox 下点 “Add to cart”,无论添加是否成功,系统没有提示(购物车有个选项是添加商品后留在当前页面),非得 F5 刷新后才能看到成功或错误信息。Safari 下正常,IE 下未实测。

    我原以为是 Magento cache 的问题,但禁用 Magento cache 后问题依旧。而且,只有 B 服务器才有这样的毛病。想来半天,觉得跟服务器参数有关。

    于是我查看了 Magento 在两台服务器的 http header,发现 B 服务器多了 cache 和 expiry 等 headers。这才特别关注了一下 nginx 的配置问题,发现 B 服务器的 server {} 里有一句 expires 1d; 不知这句是谁写到 nginx conf 文件里。这指名 Firefox 直接从本地读取,除非 F5。去掉 expires 这条目就好了。

  • Self-contained form

    Self-contained form
    Self-contained form

    视表单为一个对象

  • Knockout background using Photoshop action

    Knockout Background Using Photoshop Action
    Knockout Background Using Photoshop Action

    抠图是我最不想干的活。

  • My worry about Linksys wireless security

    前文提到 Linksys IP Camera 只能连入 Linksys wireless router,一开始就不喜欢厂家设置人为技术障碍的做法。细想之下,更觉得 Linksys wireless 安全机制堪忧。

    因为 Linksys WVC210 wireless IP camera 在设置无线联网时,只问一个 SSID,只要是 Linksys wireless router,不需密码就自动联入?如果是别人家的 Linksys wireless router 怎么办?虽然我凭着一个 Linksys WVC210 wireless IP camera 也控制不了别人家的网络设备,但如果我能对 Linksys WVC210 wireless IP camera 进行编程,是不是就相当于在别人家放置了颗隐形炸弹?Linksys wireless 或许有它独到之处,或许能隔离自动联网的设备,但我总觉得 wireless device isolation 不如直接用 password 来得更安全(至少心理上更舒服)。

  • Elements of same name in Zend_Form

    It is a rigid rule that Zend_Form can not have elements of same names. If I add a second element with the same name, the first one will be overwritten.

    When I started to use Zend_Form, I thought this rule makes life difficult. For example, if the form have “Next” and “Previous” buttons, I must give them different names. How can I tell which button is clicked? I must go through all names. I thought if these buttons could have same name but different value, it was easier to tell which button was clicked.

    It was before long I started to enjoy this rigid rule. Take the above example for example, it is NOT a good practice to judge which button was clicked by its value. Because for an internationalised program, the value may change and that is out of the programmers’ control.

    What if I want to add 5 text fields for people to fill in information like team members’ name? Two solutions. The first one looks stupid but I did not come across the second one at first.

    Solution 1:

    class MyNamespace_MyText extends Zend_Form_Element_Text {
    	protected $_name = "text";
    
    	public function init() {
    		static $sequence = 0;
    		$this->id = $this->_name . '_' . $sequence;
    		$this->_label = "Label " . ($sequence + 1);
    		$this->_name = $this->_name . '[' . $sequence . ']';
    		$sequence ++;
    	}
    }
    

    Solution 2:

    for ($sequence = 0; $sequence < 5; ++$sequence) {
    	$element = Mage::getModel('moduleName/modelName', "$sequence")
    				->setBelongsTo('text'); //my form is inside Magento
    }
    
  • Limitation of Mage::getModel method

    Magento getModel can not initialise an instance whose class requires more than 1 argument.

    I assume Magento native classes can explode options from the first argument to satisfy getModel. However, if I want to use 3rd party class like Zend_Form_Element inside Magento, there is no ways to use getModel to achieve the same result as

    $element = new Zend_Form_Text('name', $options);
    

    because

    $element = Mage::getModel('moduleName/modelName', 'name');
    

    takes 1 argument which is ‘name’ only. No way to pass $options on.

  • Drupal on php 5.3.0

    今天想安装 drupal,装了N遍终于成功。一开始想装6.14版,安装过程开始时,我按提示把 sites/default 目录设置可写,把 default.settings.php 改名为 settings.php(提示不准确!),同时设置可写,结果在数据库安装页面反复过不去。

    我联想到 Magento,猜想可能是因为 drupal 6.14 与 php 5.3.0 不兼容。

    那再试试 drupal 5.20 吧。数据库安装页面倒过去了,安装能结束,但抛出一大屏错误。试着进入后台,每个页面都抛出错误,有些功能执行不了,比如修改口令。这样怎么行?继续研究。

    我又看到 drupal 6.14 release notes,说 drupal 从 6.14 起 compatible with php 5.3.0 out of box。啊?说得这么斩钉截铁,那我重新再试。

    终于发现有人提到 drupal 6.14,sites/default 目录下不可没有 default.settings.php,也不可没有 settings.php。压缩包里只有 default.settings.php,所以提示说把它改名 settings.php 是误导,正确的做法是,新建一个 settings.php(可以是空文件),或者拷贝 default.settings.php。这下安装通过了,但还是抛出一堆错误,并不比 drupal 5.20 少。

    想了一下,可能是因为我没有给 drupal 6.14 一个全新的数据库,它是覆盖在原 5.20 的数据库上的,看来 6.14 安装过程不能自动升级数据库。于是再来一遍,这样终于成了(少数页面仍有小量错误)。

  • PDT path mapping

    今天折腾了一个晚上,终于明白一个道理:PDT 下,入口文件不能使用 path mapping,服务器上必须有入口文件才能 debug on server。入口文件所调用的文件才能 path map。