We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Page timeout 30 seconds + threading?

I have a form where a user enters a bunch of x/y coordinates. I am modeling a freezer.

Freezers have 1-N racks, each rack has 1-N boxes, and each box has 1-N grids.

I have a bunch of for loops that look sort of like this in the controller:

for($i = 0 ; $i < $numracks ; $i++){
    $rack = new Rack();
    $rack->assign(array(...));
    $rack->create();
    for($j = 0 ; $j < $numboxes ; j++){
        $box = new Box();
        $box->assign(array(...));
        $box->create();
        for($k = 0 ; $k < $numgrids ; $k++){
            $grid = new Grid();
            $grid->assign(array(...));
            $grid->create();
        }
    }
}

And php is timing out after 30 seconds. Is there some way for me to spin this block of code off into its own thread in Phalcon? I don't particularly want to increase the timeout time... rumracks is on the order of 10, and boxes and grids are like 100 so this is supposed to create hundreds of thousands of database objects :(

and if you use raw sql?



8.3k

this is supposed to create hundreds of thousands of database objects

There are two possible solutions:

  1. Adding records in pieces or even one by one (user creates a rack then adds a box etc.)
  2. Queue system: https://olddocs.phalcon.io/en/3.0.0/reference/queue.html
edited Feb '18

This should work faster, but with huge record count you may need to adjust timeout:

for($i = 0 ; $i < $numracks ; $i++){
    $this->db->insertAsDict('racks', [...]);
    $id = $this->db->lastInsertId();
    for($j = 0 ; $j < $numboxes ; j++){
        $this->db->insertAsDict('boxes', [...]);
        $id = $this->db->lastInsertId();
        for($k = 0 ; $k < $numgrids ; $k++){
            $this->db->insertAsDict('grid', [...]);
            $id = $this->db->lastInsertId();
        }
    }
}

If this does not work for the task, I would probably use Queue like Michael suggested.

edited Feb '18

Hot sizzling call girls in Bangalore available 24X7 for full satisfaction. You will get affordable, rewarding Escorts in Bangalore Service, Hire Model Bangalore Escorts. So hire an escort when you are leading a stressful life. So prepare yourself for an amazing and beautiful experience. You can find at https://www.boldschoolgirl.com/ here and Book Now.

@boldschoolgirl nah, we programmers are shy creatures, we dont just mingle with beautiful women :D