spatie / async

Easily run code asynchronously
https://spatie.be/en/opensource/php
MIT License
2.65k stars 179 forks source link

Trait 'Spatie\Async\Process\ProcessCallbacks' not found #200

Closed EmanuelSorin closed 1 year ago

EmanuelSorin commented 1 year ago

Hello I am getting this error : PHP Fatal error: Trait 'Spatie\Async\Process\ProcessCallbacks' not found in /var/www/mubu-cscart/app/lib/vendor/async-master/async-master/src/Process/ParallelProcess.php on line 12

I get all files, and a Pool is created

$files = glob('/var/www/mubu-cscart/app/lib/vendor/async-master/async-master/src/*.php');
foreach ($files as $file) {
    require($file);   
}
$files = glob('/var/www/mubu-cscart/app/lib/vendor/async-master/async-master/src/Output/*.php');
foreach ($files as $file) {
    require($file);   
}
$files = glob('/var/www/mubu-cscart/app/lib/vendor/async-master/async-master/src/Process/*.php');
foreach ($files as $file) {
    require($file);   
}
$files = glob('/var/www/mubu-cscart/app/lib/vendor/async-master/async-master/src/Runtime/*.php');
foreach ($files as $file) {
    require($file);   
}
use Spatie\Async\Pool;

Any ideas?

staatzstreich commented 1 year ago

Hey... In my opinion you should use:

require '/var/www/mubu-cscart/app/lib/vendor/autoload.php';

use Spatie\Async\Pool;

...

without that globbing / foreach and require

Have a awesome Day! best, Michael

EmanuelSorin commented 1 year ago

Tried that but I get the same error, I am executing from console

staatzstreich commented 1 year ago

For me it looks that you have downloaded the code as zip and not installed via

composer require spatie/async
EmanuelSorin commented 1 year ago

I am working with cscart, do you know how to use their composer to install the package?

staatzstreich commented 1 year ago

I am sorry… No Idea. Never heard something about cscart

EmanuelSorin commented 1 year ago

No problema, in cscart I could install it, but I need to execute my code from console, without the use of cscart composer, how can I install package so I can use it with command "php file.php" and it to work?

staatzstreich commented 1 year ago

If cscart have it’s own composer you have to ask the cscart Team.

for all composer Packages i used… it is no Problem to run from console if your file include the autoload.php from the vendor folder…

EmanuelSorin commented 1 year ago

I installed composer from console, and used it to install this repository, but where is that autload.php in php files?

EmanuelSorin commented 1 year ago

Looks like I managed to add it to composer and work from console! But now I have the problema that it seems to not recognize functions or vairables created before or out of pool, how can I fix that?

EmanuelSorin commented 1 year ago

e

And I am getting this error

EmanuelSorin commented 1 year ago

Right now I am working with Tasks, but I get error This is my code: `class MyTask extends Task { public $store; public function __construct(array $store) { $this->store = $store; } public function configure() { // Setup eg. dependency container, load config,...

    require '/var/www/mubu-cscart/app/lib/vendor/phpmailer/phpmailer/src/Exception.php';
    require '/var/www/mubu-cscart/app/lib/vendor/phpmailer/phpmailer/src/PHPMailer.php';
    require '/var/www/mubu-cscart/app/lib/vendor/phpmailer/phpmailer/src/SMTP.php';
    //CONSEGUIMOS LOS FICHEROS NECESARIOS DE WOOCOMMERCE PARA QUE FUNCIONE
    $files = glob('/var/www/mubu-cscart/app/lib/vendor/woocommerce/wc/src/WooCommerce/*.php');
    foreach ($files as $file) {
        require($file);   
    }
    $files = glob('/var/www/mubu-cscart/app/lib/vendor/woocommerce/wc/src/WooCommerce/HttpClient/*.php');
    foreach ($files as $file) {
        require($file);   
    }

}

public function run()
{
    // Do the real work here.
}

}`

foreach ($stores as $store) { $pool->add(new MyTask($store)); } $pool->wait();

And this is the error i am getting image