Home >Backend Development >PHP Tutorial >Secondary development and modification implementation of PinPHP background batch collection function_PHP tutorial

Secondary development and modification implementation of PinPHP background batch collection function_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:58:211065browse

I have been using PinPHP for a while. I used PinPHP to set up an environment on Sae and ran "Fashion Beauty" for about a month. So I have been studying this program recently and doing some secondary development. , add some of your own ideas. For example, the blog posts I wrote before: adding Renren account login (actually also doing Taobao login, just using it in Taobao application center), modifying PinPHP collection.

Okay, today I will talk about the secondary development and modification implementation of the PinPHP background batch collection function. I first connected to pinphp and used the 2.1 beta version,

Up to now, the official version 2.2 has been released, but unfortunately, the batch collection function that everyone was looking forward to has not been released as expected, so I tried to modify it myself,

Actually, the program was written half a month ago, but I am just using it myself. On the one hand, I am a little busy at work, and on the other hand, I have been testing it for a while and improving it by the way.

It is very simple to implement the original implementation. The main thing is to modify the collection interface and add a few checkboxes to pass the IDs, keywords, etc. to be collected.

1. Modify: adminTpldefaultitems_collectcollect.html page, about 28 lines.

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com]

The official may have tried to do batch collection, because the code for batch collection on this page has not been completed and is just commented.

2. Then add a function to adminLibActionitems_collectAction.class.php and slightly modify the original collection function

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] function ajaxCollect(){
set_time_limit(0);
$subname=$_REQUEST['subname'];
$arrUrls=array();
foreach($_REQUEST['cate'] as $k=>$v){
if(!empty($subname[$k])){
$arrUrls[]='http://mmlike.sinaapp.com/mlike_admin.php?a =taobao_collect_jump&m=items_collect&pages=1&cate_id='.$v.'&keywords='.$subname[$k];
}
}
$this->assign('url',json_encode($arrUrls ));
$this->display('ajaxCollect');
}

This sentence contains some information that you should pay attention to

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] $arrUrls[]='http://mmlike.sinaapp.com/mlike_admin.php?a=taobao_collect_jump&m=items_collect&pages=1&cate_id='.$v.'&keywords='.$subname[$k];

page=1 is to collect one page, with 40 products per page. If you need to collect more products at one time, you can modify it yourself, but it is not recommended to fill in a too large value. On the one hand, the collection time is long, and on the other hand, Taobao api Requests may be made too frequently.

Modify the public function collect() function, and change the if in the first half to

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] if(isset($_REQUEST['dosubmit'])){
/******Batch collection*******/
$cate=implode(',',$_REQUEST['cate']);
$ this->ajaxCollect();
//header("location:".U('items_collect/taobao_batch_collect_jump?act=batch&cate='.$cate));
exit;
/******Batch collection*******/
}

3. Add one to the template, adminTpldefaultitems_collectajaxCollect.html

Copy to ClipboardLiehuo.Net Codes引用的内容:[www.bkjia.com]



ajax










Friends who know php and js should understand. Put the assembled collection url in js in json form, use the setInterval timer to execute ajax requests regularly, and traverse all urls

Until done. At the beginning, I used setInterval instead of direct for traversal because I was worried that if there were too many categories, requesting the Taobao API too frequently would result in partial collection failure.

The ajax above uses asynchronous requests. I tried to use synchronization to obtain it before, in order to conveniently capture which collection was successful and which one was unsuccessful, so that I can manually collect it,

After testing for a while, although the effect is achieved, due to too many categories, the browser will freeze when collecting at one time, and the total collection time will become longer and longer. Still using

Asynchronous, no lag, shortening the collection time. Although failure capture can also be achieved, more code needs to be modified. I have time to study this. The current effect is as follows



The progress is displayed in % ratio. Finally, the degree of completion and the number of failures will be displayed. As for the failed ones, collect them again, or you can check which ones have not been collected and collect them manually.

After this modification, the original collection function can also be used normally.

To reiterate, I am using the test version of pinphp2.1. If you want to modify other versions, you can use it as a reference. The following is the packaging of the modified files. It is not recommended to overwrite it directly. It is best

Compare the code. If you want to overwrite it, please back up the original file first for recovery.

Click to download: pinphp batch collection

Tutorial source: http://meego123.net/?post=140

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363820.htmlTechArticleI have been using PinPHP for a while. I used PinPHP to set up an environment on Sae and ran "Fashion" for about a month. "Meihui", so I have been studying this program recently and doing some secondary operations...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn