PHP curl 抓取页面时的 cookie 问题

Posted on 28th October 2009 by Nio in 工作忙碌, 程序人生 - Tags: ,

使用 PHP curl 抓取页面时,可以设置 cookie 保存的文件,示例代码:


<?php
$cookie_path 'cookie.txt';
$ch curl_init();
curl_setopt($chCURLOPT_COOKIEFILE$cookie_path);
curl_setopt($chCURLOPT_COOKIEJAR$cookie_path);
//....
?>

特别需要注意的是,在完成抓取之后,需要把 cookie 文件删除,否则下次抓取时会自动使用原有的 cookie 数据,从而导致一些预想不到的错误(我们今天就被这个问题折腾了很久 :( )。

Chunking Large Queries with Iterators in PHP

Posted on 8th October 2009 by Nio in 程序人生 - Tags:

Chunking Large Queries with Iterators in PHP

When executing large queries it's usually best not to load the whole result set in one go. Memory isn't infinite and PHP isn't renowned for handling it very well. So the obvious answer is to chunk the large query in to lots of smaller queries. This is a simple method I use for hiding the fact the query is being chunked behind an iterator.