Hongmu Notes
Home Program Notes Empire cms 4 million article homepage high-efficiency calling code
Program Notes Empire cms

Empire cms 4 million article homepage high-efficiency calling code

Empire cms 4 million article homepage high-efficiency calling code

Since my server configuration is relatively poor, using sql's rand() to randomize is definitely not possible. It is too slow, so I changed my mind and first built a table with two fields, one is the article ID and the other is the column ID. Then I use this table to perform regional randomization, so that I can randomly The high efficiency of the machine was achieved, but there was a problem. Using SQL was unreliable, so I wrote a PHP code. After testing, the homepage could be loaded within two seconds, but it was always random and bad, so I used my caching plug-in to fix the page.... This is all for the future.

<?php
$file_cache = "./news.json";
//缓存整个news表的数据
if(!file_exists($file_cache) || time()-filemtime($file_cache)>86400){
    //查询分类
    $hm_class=$empire->query("select classid from {$dbtbpre}enewsclass");   
    while($hm_r=$empire->fetch($hm_class))
    {
        //查询分类下面的所有id
        $hm_news=$empire->query("SELECT id FROM `{$dbtbpre}ecms_news` WHERE `classid` = {$hm_r[classid]}");   
        while($hm_nr=$empire->fetch($hm_news))
        {
            $news_data[$hm_r['classid']][] = $hm_nr[id];
        }
    }
    file_put_contents($file_cache,json_encode($news_data));
}
//获取缓存数据表
$file_arrs = json_decode(file_get_contents($file_cache),true);
//根据数据表获取id
foreach($file_arrs as $k=>$v){
    //增加变量
    for ($rani=1; $rani<=30; $rani++){
        $rand_id.= $v[mt_rand(0,count($v)-1)].",";    
    }
    $rand_id = rtrim($rand_id,",");
    $rand_data[] = $rand_id;
    $rand_id = "";
    $rani=1;
}
?>

I wrote it for two days, thought about it, and finally tested it for a long time before writing it like this. If the server configuration is still too small, you can try to split the cache file and call it. Of course, this requires you to open it again.
To use the code, first put the PHP code at the top of the home page template, and then you can directly call the universal tag.

[ecmsinfo]1,20,32,1,0,13,0,"id in ($rand_data[0])"[/ecmsinfo]
[ecmsinfo]2,20,32,1,0,13,0,"id in ($rand_data[1])"[/ecmsinfo]
[ecmsinfo]3,20,32,1,0,13,0,"id in ($rand_data[2])"[/ecmsinfo]

For example, if you don't know PHP when calling like this, you should first understand the PHP syntax. You can ask me to improve the code!

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Empire CMS database statement & SQL statement format

Empire CMS database statement & SQL statement format Program Notes Empire cms

Introduction to Imperial CMS extended SQL program writing, basic examples of Imperial CMS database statements & SQL statement formats: Note: The following examples are based on placing PHP files in the system root directory. Example 1: Connect to MYSQL program. (a.php)<?php require('e/class/connect.php'); //Introduce database configuration files and public function files requ…
👁 351
Empire CMS obtains the system COOKIE variable function getcvar()

Empire CMS obtains the system COOKIE variable function getcvar() Program Notes Empire cms

Get the system COOKIE variable function syntax: getcvar($var,$ecms) Description: $var: is the variable name $ecms: 0 is to set the foreground COOKIE variable, 1 is to set the background COOKIE variable. This parameter can be omitted and defaults to 0. Usage example: getcvar('mlusername'), get the user name of the front-end login member getcvar('loginu...
👁 296
Empire CMS smart label call field collection

Empire CMS smart label call field collection Program Notes Empire cms

Collect and classify all fields that support smart tag calls into Empire CMS smart tags: [e:loop={column ID/topic ID, number of items displayed, operation type, only display pictures with titles, additional SQL conditions, display sorting}] Template code content [/e:loop] Calling time: <?=date('m-d',$bqr[newstime])?> <?=dat…
👁 3749

Recommended reading

Squeegee Machine & Hot Melt Machine Website Template – 0676

Squeegee Machine & Hot Melt Machine Website Template – 0676 Practical Collection Yiyou template

An eYouCMS website template designed for the dispensing machine and hot-melt machine industries. Its professional industrial design style is ideal for showcasing dispensing machine products, hot-melt machine equipment, technical specifications, and industrial applications. This template helps machinery and equipment manufacturers showcase their products online and attract customers from the electronics and industrial sectors. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS...
👁 50
Construction Machinery – Earth Excavation and Transport Equipment Website Template 0677

Construction Machinery – Earth Excavation and Transport Equipment Website Template 0677 Practical Collection Yiyou template

This EyouCMS template is designed for the construction machinery (excavation and transportation equipment) industry. Its professional yellow color scheme is ideal for showcasing excavation and transportation machinery, engineering vehicles, technical specifications, and construction case studies. It enables construction machinery companies to showcase their products online and attract clients in the infrastructure and mining sectors. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Issues During EyouCMS Installation...
👁 58
Responsive Water Supply Pipeline Valve Website Template 0678

Responsive Water Supply Pipeline Valve Website Template 0678 Practical Collection Yiyou template

An eYouCMS responsive website template designed for the water supply pipeline and valve industry. Its professional industrial design style is ideal for showcasing pipeline products, valve series, technical specifications, and engineering applications. This template helps pipeline and valve manufacturers showcase their products online and attract construction and industrial clients. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS...
👁 29
Resource website typecho001 template

Resource website typecho001 template Program Notes Typecho

typecho001 template template please do not modify the folder name of this template. The folder name is: typecho001 1.4 Fix the js output problem on the article page 1.3 Fix the error prompt when the plug-in is not installed Optimize the list page code output 1.2 Fix the comment function and add a custom homepage title 1.1 Fix the comment reply asymmetry function Add a separate title setting function on the homepage Add the website favicon.ico icon Add one...
👁 198
Fully hydraulic dual drive excavator and roller website template 0679

Fully hydraulic dual drive excavator and roller website template 0679 Practical Collection Yiyou template

This set of eyoucms templates is suitable for the fully hydraulic dual-drive excavator and road roller industries. The design style is yellow and professional. It can display excavator and road roller products, engineering machinery and equipment, technical parameters and construction cases. It helps construction machinery companies display their products online and attract infrastructure and mining customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Yiyou CMS security...
👁 56
Modification of typecho paging style

Modification of typecho paging style Program Notes Typecho

Sir, times have changed! Typecho is currently the most perfect solution, because Baidu can only see the code of fixed thinking. The actual generated HTML code is breathtakingly clean and fully customized, including adding classes to the li element, adding classes to the a element, adding classes to the previous page and next page, and removing the li tags that come with typecho to express more. I can even add some text to the content inside...
👁 517