Saving of bean is too slow and not complete


I want to save a bean object in while loop but the saving is too slow and it’s not complete, it saves just half, I don’t understand. I have 2017 recordings to save.

Someone can help me ?? :frowning: :frowning: :frowning:

This is my code :

$rel_emp =new FOI_Emplacements_Evenements();

It’s hard to say what’s going on without more information. Are there any logic hooks or custom logic for the bean?

Saving 2017 records will take a bit of time, it’s possible that the PHP timeout is being reached. You could possibly set the limit in each loop:

An alternative would be to check for existing records and skip those which have already been saved so that, at least, multiple runs will save more of the records.

Hope this helps,

I have /custom/modules/FOI_Evenements/logic_hooks.php file with an after_save logic hook :

// Do not store anything in this file that is not part of the array or the hook version.  This file will	
// be automatically rebuilt in the future. 
 $hook_version = 1; 
$hook_array = Array(); 
// position, file, function 
$hook_array['after_save'] = Array(); 
$hook_array['after_save'][] = Array(1, 'Creation Emplacement', 'custom/modules/FOI_Evenements/hook.php','Evenement', 'creationEmp'); 


and the hook.php file with this part of code :

$rel_emp =new FOI_Emplacements_Evenements();

this code is supposed to create a new bean FOI_Emplacements_Evenements. and there is 2071 Emplacements_Evenements, but it saved just half of 2071, I don’t understand why it stopped ??

I change the set_limit_time, but there is the same problem.

To confirm you want to save 2071 new records everytime a FOI_Evenements is created or edited?

Long running actions generally shouldn’t go into logic hooks. See here for information about adding a task to the job queue:

Saving Beans tends to be slow and timeout

Have you considered changing your code to use an sql statement instead?

This tends to be much quicker and you can often write the sql so that it modifies multiple records in one go