M
M
Mikhail Smirnov2017-05-25 17:17:35
PHP
Mikhail Smirnov, 2017-05-25 17:17:35

Why does file_put_contents() work strangely in Bitrix?

Catalog export script example

$arSelect = [ 
       'ID', 'IBLOCK_ID','IBLOCK_CODE','IBLOCK_SECTION_ID','NAME', 'LIST_PAGE_URL', 'DETAIL_TEXT', 'DETAIL_PICTURE', 'DETAIL_PAGE_URL', 'SECTION_PAGE_URL', 
       'PROPERTY_CML2_ARTICLE','PROPERTY_MODEL','PROPERTY_BRAND', 'PROPERTY_GABARITY_VKHSHKHG_SM' 
   ]; 
   $arFilter = Array( 
       "IBLOCK_ID"=> $iblockId, 
       '!IBLOCK_SECTION_ID' => SECTION_NEMATRITSA_ID, 
       "PROPERTY_COPY_PROPERTIES" => 1, 
   ); 

   $res = \CIBlockElement::GetList(Array('IBLOCK_SECTION_ID'=>'ASC', 'PROPERT_BRAND_VALUE' => 'ASC'), $arFilter, false, false, $arSelect); 

   $arElements = []; 
   $i = 0; 
   while($ob = $res->GetNextElement()) { 
       $fields = $ob->GetFields(); 
       $fields['PRODUCT_INFO'] = CCatalogProduct::GetByID($fields['ID']); 

       if ($fields["~DETAIL_PICTURE"] != null) { 
            $resizeImage = CFile::ResizeImageGet( 
               $fields["~DETAIL_PICTURE"], 
               array("width" => 150, "height" => 150), 
               BX_RESIZE_IMAGE_PROPORTIONAL, 
               true 
           ); 
        
           if (!$resizeImage) { 
               $fields['DETAIL_PICTURE'] = '/local/templates/eshop_bootstrap_black/components/bitrix/catalog.element/.default/images/no_photo.png'; 
           } else { 
               $fields['DETAIL_PICTURE'] = $resizeImage['src']; 
           } 

           $fields['IMAGE_PATH'] = $_SERVER["DOCUMENT_ROOT"] . $fields['DETAIL_PICTURE']; 
       } else { 
           $fields['IMAGE_PATH'] = $_SERVER["DOCUMENT_ROOT"] . '/local/templates/eshop_bootstrap_black/components/bitrix/catalog.element/quick-view/images/no_photo.png'; 
       } 

       $arElements[] = $fields; 
       file_put_contents('test.csv', $fields['IMAGE_PATH'] . "\r\n", FILE_APPEND); 
       $i++; 
   }

the problem manifests itself when writing to a file, PHPExcel is initially used, but the file_put_content function also does not work.
When using file_put_contents, the function stops writing data to the file at about 3000 - 4000 lines, and the last line is different each time, in total there are 7300 elements in the directory, the
cycle works completely, but data is no longer written to the file, we try to remove a piece of code from the script:
$resizeImage = CFile::ResizeImageGet( 
               $fields["~DETAIL_PICTURE"], 
               array("width" => 150, "height" => 150), 
               BX_RESIZE_IMAGE_PROPORTIONAL, 
               true 
           );

and everything works fine, the data is written to the file, but with CFile::ResizeImageGet it just stops writing to the file (file_put_contetns returns false)
tell me what could be the problem, because of which file_put_contents may stop working when using CFile::ResizeImageGet
CentOS, php 7.0 , Bitrix web environment.
There are no errors in the logs.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Georgy Bondarenko, 2017-06-02
@Koen777

And what are the characteristics of a virtual machine? Maybe there is not enough memory in the buffer during generation?
In general, it is preferable to use spl-objects. Here is your

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question