Executing slow function with Vroom (shutdown event)

Hi community, I have this function:

function elgg_webcam_convert_file($file, $ext) {

  ...ffmpeg conversion process..

} 

and I call it from the upload file action:

elgg_register_event_handler('shutdown', 'system', function () use ($file) {
           elgg_webcam_convert_file($file, 'mp4');
    });

But the function doesn´t run.

What I´m doing wrong?

I´ve Elgg 2.2

 

  • The code seems correct, though shutdown event may not always behave as you want it. Do you have vroom plugin installed?

  • Yes I´ve Vroom enabled and working.

    I´ve tried in start.php with:

    elgg_register_event_handler('update:after', 'object', 'elgg_webcam_make_web_compatible');
    
    function elgg_webcam_make_web_compatible($event, $type, $entity) {
      ...  
      ...    
        elgg_register_event_handler('shutdown', 'system', function () use ($file_guids) {
               elgg_webcam_vroom($file_guids);
        });
    }
    
    function elgg_webcam_vroom($file_guids) {
        
    ...
    
    ...
            elgg_webcam_convert_file($entity, 'mp4');        
        }
    }

    And it works, but I need the ffmpeg conversion at file upload, I tried with:

    elgg_register_event_handler('upload:after', 'object', 'elgg_webcam_make_web_compatible');
    
    elgg_register_event_handler('create', 'object', 'elgg_webcam_make_web_compatible');

    But doesn´t work, any idea how can I defer the ffmpeg process after file upload?

  • I am confused. The code you say works defers it already, so what doesn't work? Are you saying it works with update event and not the create event?

  • It looks like like you are modifying my code from elgg_file_viewer or working with a plugin that stole/recycled my code, so why are not just using the config values, and trying to make this work with closures instead?

  • Are you saying it works with update event and not the create event?

    Yes

    It looks like like you are modifying my code from elgg_file_viewer

    Yes Ismayil, I looked for working vroom examples and I try with your plugin code.

    make this work with closures instead?

    I dont unsderstand it, I see you use elgg_get_config/elgg_set_config in your functions but neither works. 

  • Are you using the file plugin? Perhaps the upload script calls save before moving the file to filestore.
    You are using anonymous closures as callback handlers, which should work, but harder to follow or debug

  • My plugin handles the file upload from videojs-record and javascript to php, and the file is saved ($file->save();) to filestore after, it is so strange...

    Finally I moved the process to cron.

    Thanks Ismayil.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking