Crawling site pages to form cache on D7 and using software
Rus
Eng
Обход страниц сайта для формирования кеша на D7 и с помощью софта
I solve complex technical challenges for Bitrix and 1C—ranging from auditing existing code to website development and configuring complex integrations—with a guarantee of results.
Recommended

Website hosting

If you are choosing hosting for your project, I recommend Timeweb. Modern infrastructure, a wide range of plans from starter options to high-load VPS, and responsive tech support that actually helps instead of sending template replies. I host some of my own projects there and recommend it to my clients.

Go to site Affiliate link. The price remains the same for you.

All English-language materials have been translated fully automatically using the Google service

To form a cache on the site and cut preview images, sometimes the task is set to bypass all the pages of the site. The easiest way to do this is in two ways: with your own script or using third-party software

  $ DOCUMENT_ROOT = $ _SERVER ['DOCUMENT_ROOT'];
$ domainName = 'http://www.site.ru';
$ iblockIds = [2,];
$ pageNum = 20;
 
define ('NO_KEEP_STATISTIC', true);
define ('NOT_CHECK_PERMISSIONS', true);
define ('CHK_EVENT', true);
 
require ($ _ SERVER ['DOCUMENT_ROOT']. '/bitrix/modules/main/include/prolog_before.php');
 
@set_time_limit (0);
@ignore_user_abort (true);
 
if (\ Bitrix \ Main \ Loader :: includeModule ('iblock')) {
 
    $ urls = array ();
 
    foreach ($ iblockIds as $ iblockId) {
 
        $ sectionIterator = CIBlockSection :: GetList (
            array (),
            array (
                'IBLOCK_ID' => $ iblockId,
                'ACTIVE' => 'Y',
                'GLOBAL_ACTIVE' => 'Y',
            ),
            array (
                'ELEMENT_SUBSECTIONS' => 'Y',
                'CNT_ACTIVE' => 'Y',
            ),
            (
                'ID',
                'IBLOCK_ID',
                'SECTION_PAGE_URL'
            )
        );
 
        while ($ section = $ sectionIterator-> GetNext ()) {
            for ($ i = 1, $ count = ceil ($ section ['ELEMENT_CNT'] / $ pageNum); $ i <= $ count; $ i ++) {
                $ urls [] = sprintf ('% s? PAGEN_1 =% d', $ domainName. $ section ['SECTION_PAGE_URL'], $ i);
            }
        }
 
        $ elementIterator = CIBlockElement :: GetList (
            array (),
            array (
                'IBLOCK_ID' => $ iblockId,
                'ACTIVE' => 'Y',
            ),
            false,
            false,
            array (
                'ID',
                'IBLOCK_ID',
                'DETAIL_PAGE_URL'
            )
        );
 
        while ($ element = $ elementIterator-> GetNext ()) {
             $ urls [] = $ domainName. $ element ['DETAIL_PAGE_URL'];
         }
     }
 
    foreach ($ urls as $ url) {
        @file_get_contents ($ url);
        @file_put_contents ($ _ SERVER ['DOCUMENT_ROOT']. '/import.log', $ url. "\ n", FILE_APPEND);
    }
}  

An example of running a php script from the console:

  php -f /var/www/site.ru/import.php &  

Before I came across this script, and now I also use the program SiteAnalyser , which not only automatically crawls all pages, but also generates any useful information for thought

    

Reprint of material:


Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Please message me to discuss the task. I work remotely and officially (as a self-employed professional); my hourly rate is 1,800 RUB, and I can dedicate 3–4 hours a day to the project. I respond quickly, and the consultation is free.

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site