PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 21, 2022

[FIXED] CakePHP 3.0 "thread class not found"

 February 21, 2022     cakephp, cakephp-3.0, multithreading, php     No comments   

Issue

I want to implement the threading concept in CakePHP 3.0 , But when I try to extend the thread class, it gives an error of "Thread class not found"

I have also implemented it in core php and its working as expected, But somehow its not working with cakephp.

Here is the corephp code

<?php

class AsyncOperation extends Thread {

    public function __construct($arg) {
        $this->arg = $arg;
    }

    public function run() {
        if ($this->arg) {
            $sleep =  rand(1,60);
            for ($i=0; $i < 100 ; $i++) { 
                sleep(1);
                echo $this->arg."----------->".$i."<br/>";    
            }
        }
    }
}

class CallingClass {
    public function runScript($var)
    {
        print_r("start run script");
        $th = new AsyncOperation($var);
        $th->start();
        print_r("continue running");

    }
}

$wow =  new AsyncOperation("First");
$wow->start();
$wow2 =  new AsyncOperation("Last");
$wow2->start();
?>   

And in CakePHP 3

class AsyncOperation extends Thread

Solution

Just add simple line

use Thread;


Answered By - Vivek Doshi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing