2

I'm trying to run a code that would execute a function and just continue with the loop without waiting for the function executed to finish. something like this:

  public static function refreshData(){
        foreach (glob(__DIR__.'/tabs/*.pr') as $file) {  
            $path_parts = pathinfo($file);     
            $name = $path_parts['filename'];

            $new = Readers::reset($name);
            $new->processData();

        }

I don't need the processData function to block my code. I just want to execute it and continue with the rest of the code, which in that cause is to continue looping.

Cayenne
  • 94
  • 9
  • Introduce a queue for the tasks and run background workers to process tasks from the queue. – Oluwafemi Sule Sep 26 '18 at 05:40
  • how can I do that? – Cayenne Sep 26 '18 at 05:41
  • I guess this can help you: https://stackoverflow.com/questions/1993036/run-function-in-background – dWinder Sep 26 '18 at 05:54
  • Let's describe handling one type of task. You persist the task definition (List data structure in Redis database is handy here). A task defn can be arguments for the task to run. Implement a [worker](https://secure.php.net/manual/en/class.worker.php) to pull task defns and run them. Using [Redis lists](https://redislabs.com/ebook/part-1-getting-started/chapter-1-getting-to-know-redis/1-2-what-redis-data-structures-look-like/1-2-2-lists-in-redis/) as transport can also be replaced with pubsub. Choose this if there is a guaranteed listener and tasks are processed faster than retrieval. – Oluwafemi Sule Sep 26 '18 at 06:00

0 Answers0