Handle Of Long Running Process In Yii


(Adinugro) #1

Dear All,

I have developed application for managing warehouse. It is simple in and out warehouse transaction. However, the item is about 900. The problem is when I generate monthly report, it will produce minimum 1800 rows (Initial balance and final stock). I always got reach maximum execution time. I have no idea how could I display the result on screen without reach maximum execution time.

One way that I can think of is to generate oflline into pdf/excel so that the user can see the report from a link. However, this approach has some limitation on how could I trigger the generation from web application.

Is there any yii way to do this?

Thank you in advance.

Daniel


(Kburton) #2

This is a PHP or Apache configuration issue. Try this function first.


(Pr0j3ct A1ex) #3

I would use ajax.

Query how many results there will be then use ajax to request x amount of rows at a time.


(Adinugro) #4

Hi,

Thank you for the great idea. However, how can I make x requests of ajax calls? I calculate that my algorithm is ok for around 50 items.

Cheers,

Daniel


(Pr0j3ct A1ex) #5

When the page is first requested get a count of all the rows that will be returned.

Then have an ajax request call a controller action and return 50 results.

Once this has been returned and rendered into the report request the next 50 then repeat until you have all records.


(Adinugro) #6

Hi,

I create a CActiveForm and submit the ajax call via ajax button.




....

<div class="actions">

    <?php echo CHtml::ajaxButton('Generate', $this->createUrl('/invoice/periodeInvoicing'), array(

        'type' => 'POST',

        'beforeSend' => 'function(data,status){ $("#invoice_btn").attr("disabled", "disabled"); $("#invoice_btn").removeClass("primary"); }',

        'success' => 'invoiceSaved'), array('id' => 'invoice_btn', 'class' => 'btn primary')); ?>

</div>

....



How could I iteratively submit the form (simulating ajaxButton click) ?




<script type="text/javascript">

    function invoiceSaved(data, textStatus, XMLHttpRequest) {

        $.fn.yiiGridView.update('invoice-grid');

        var obj = jQuery.parseJSON(data); 

        jQuery('#alert').bootAlert('alert', obj.status, obj.msg);

        if(obj.totInvoices <= 0) {

            $('.invoice-form').hide();

        } else {

             $('#invoice_btn').removeAttr('disabled');

             $('#invoice_btn').addClass('primary');

 ====> need code here to resubmit the form <=====

        }

    }

</script>



Cheers,

Daniel