How to call a function without waiting for it to finish?

2

I need to call a function in PHP that writes several records in the database which will take a lot, I need to do it in the background while PHP does something else, is it possible? If so, how?

    
asked by anonymous 04.08.2016 / 22:42

1 answer

3

You can use the PHP Thread class:

<?php

class segundoPlano extends Thread 
{
    public function __construct($sP)
    {
        $this->sP = $sP;
    }

    public function run()
    {
        //o teu código a executar;
    }
}

$segundoP = new segundoPlano($sP);
$segundoP->start();

The variable in the constructor is an example.

Note: To use this class you must install the pthreads extension .

    
05.08.2016 / 00:02