<?php
class AppDownloader
{
public function onDownloaderStart($downloader)
{
}
public function onDownloaderStop($downloader)
{
}
public function onDownloaderReload($downloader)
{
}
public function onDownloaderMessage($downloader, $parser_reply)
{
}
public function onDownloaderConnectToParser($connection)
{
}
public function onDownloadBefore($downloader, $task)
{
//比如可以在这里改变发起http请求时的上下文参数
//$downloader->httpClient->setConnectTimeout(3);
//$downloader->httpClient->setTransferTimeout(10);
//$downloader->httpClient->setProxy($proxy);
}
public function onDownloadStart($downloader, $task)
{
}
public function onDownloadAfter($downloader, $download_data, $task)
{
//比如将下载后的源数据保存到某个文件:
//file_put_contents("/path/to/downloadData.txt", $download_data);
}
public function onDownloadFail($downloader, $error, $task)
{
}
public function onDownloadTaskEmpty($downloader)
{
}
}
<?php
class AppParser
{
public function onParserStart($parser)
{
}
public function onParserStop($parser)
{
}
public function onParerReload($parser)
{
}
public function onParerMessage($parser, $connection, $download_data)
{
}
public function onParserFindUrl($parser, $url)
{
//比如当发现子URL时,可以在这里校验子url是否有效
//if(!Tool::checkUrl($url)) return false;
}
public function onParserExtractField($parser, $download_data, $fields)
{
//比如打印提取到的业务数据
//pprint($fields, __METHOD__);
//比如将数据存到mysql、redis数据库等等
//DB::save($fields);
}
}