3

I'm trying to achieve multitasking in PHP. At the moment I'm evaluating AMPHP framework, and in particular paralell and paralel-functions.

But I can't figure how is to create a method callable...

The idea is that I will have a Class with some methods and I want to instantiate multiples objects, and invoque, for each one, the same method, but in paralell, or asynchronously.

I found a TestCase in parallel-functions folder, and I can't figure out what is doing

public function testClassInstanceMethod() {
    $instance = new TestCallables;

    $callable = [$instance, 'instanceMethod'];
    $result = $callable(1);  //<-- what is (1)?
    $callable = parallel($callable);

    $this->assertSame($result, Promise\wait($callable(1)));
}

What happened if I create multiples instances?

$instances[] = new TestCallables;

I think that what I need to know first is how to create a callable class/method/function... in PHP.

Important information: This should run in web environment ( no pThreads !) in Yii Framework.

Any suggestions? Best Regards

Eddie
  • 26,593
  • 6
  • 36
  • 58
Nicolas400
  • 563
  • 1
  • 7
  • 29
  • 2
    Your title is confusing because every method/function is in essence callable. – Daan May 09 '19 at 13:57
  • In the example, 1 would be the argument to the method `instanceMethod` on the object in `$instance`. – Chris White May 09 '19 at 14:02
  • Hi @Daan , I'm trying to use this https://amphp.org/parallel-functions/ ... – Nicolas400 May 09 '19 at 15:18
  • Another idea of what I try to do is this: https://github.com/amphp/parallel but instead of "file_get_contents" function, I want to call a method in a class!, of course I willl need to pass parameters and return values! – Nicolas400 May 09 '19 at 15:37

1 Answers1

0

Data is passed between the treads/processes in serialized form, so you can't just instantiate an object in one thread/process and call the same instance's method in another thread.

I need more information to help you; your question is confusing a bit. Please show the example that doesn't work - and I'll help you to understand, why.

Edward Surov
  • 469
  • 4
  • 3