ahmadissa's avatar

Laravel insert data twice when timeout occurs (bug possibility)

I noticed laravel re-preform the insertion action when the timeout occurs

How can I shop it from retiring to insert the data again when timeout error fires ?

data loop

foreach ($comments_data as $comment_data)
                {
                    if ( ! empty($comment_data['date']))
                    {

                        $total_rating[] = $this->check_rating_value($comment_data['rating']);
                        $comment_id     = ( new Comment() )->saveComments($shop, $comment_data, $product_id, $urls, $shop_options);


                        ( new Comments_images() )->save_images($comment_id, $shop, $comment_data['images']);
                    }

                }

inserting code

public function saveComments($shop, $comments_data, $product_id, $url, $shop_options)
{
    $date = Carbon::parse($comments_data['date']);

    if ($shop_options->filter_status == 1)
    {
        $comments = str_replace(explode(',', $shop_options->filter_find_words), explode(',', $shop_options->filter_alter_words), $comments_data['comment']);
    } else
    {
        $comments = $comments_data['comment'];
    }

    $faker             = Factory::create();
    $this->shop_name   = $shop;
    $this->comment     = $comments;
    $this->rating      = $this->check_rating_value($comments_data['rating']);
    $this->product_id  = $product_id;
    $this->user_name   = $faker->userName;
    $this->product_url = $url;
    $this->created_at  = $date->toDateTimeString();
    $this->country     = $comments_data['country'];
    $this->view        = 1;
    $this->save();

    return $this->id;
}

If its a feature how can I disable it ?

0 likes
8 replies
ahmadissa's avatar

@JordanDalton

it didn't solve the issue

If the data where 100,200 .... or 400 a timeout won't fire and no duplication will occurs

but if more than that it may take up to one minutes and timeout will fire and the data will be duplicated ?!

ahmadissa's avatar

@Snapey Because the process needs more then 1 mins for 1000 reviews

it's api application

when timeout fires the process completes in background and I will get 1000 reviews even after the timeout fires but after few seconds the reviews number will be 2000

and the duplication occurs.

I want to stop this feature in laravel if possible!

Snapey's avatar

Well, I guess your API is being called twice because you take so long to process?

1 minute for 1000 - how many queries per entry (a lot I guess)

The problem lies with the sender if it is sending twice.

The problem also lies with your queries if is taking too long

Cronix's avatar

What is "timing out" exactly? Your session, or php itself? You can increase either or both.

ahmadissa's avatar

@Snapey If its besing called twice the issue will occur whether the timeout fires or not.

In my case the reviews stored successfully if not timeout fires.

I read that laravel uses queue and will try again if the system failed or timeout error fired

I haven't torched the queue , and I don't know if it happens automatically even if I didn't set it . It may be the reason.

Thank you.

ahmadissa's avatar

@Cronix it's php because the execution took too much time.

I separated the tasks but I'm trying to find a solution to prevent this issue even in case if timeout error

I will try to make new php code without laravel to see if the issue from the api or bug in laravel

Thank you

Please or to participate in this conversation.