Giter Site home page Giter Site logo

Comments (10)

walkor avatar walkor commented on May 25, 2024

Sorry, I don't have a good solution here.

from webman.

cayolblake avatar cayolblake commented on May 25, 2024

@walkor Okay. I'm thinking (out of desperation) to create the external one in onWorkerStart.

Is there a way to create a variable at onWorkerStart and use it in onMessage?

from webman.

cayolblake avatar cayolblake commented on May 25, 2024

@walkor, so I was able to set variables to be held by the Worker class (not sure if this is bad practice), yet I wasn't able to make it yet.

I am thinking about forking a new Thread for the other component in the onWorkerStart, then communicate to it (I had no idea how to do that yet).

Would that work in theory? 🤔

from webman.

walkor avatar walkor commented on May 25, 2024

You can store the data on the worker, for example.

$worker->onWorkerStart = function($worker) {
    $worker->someData = 'some data';
};
$worker->onMessage = function($connection, $data) use ($worker) {
   echo $worker->someData;
};

The fork process is not recommended. It will lead to unexpected consequences of the event extension, such as the failure of the listening socket.

from webman.

cayolblake avatar cayolblake commented on May 25, 2024

@walkor okay I understand.

Just a crazy idea. Would it be theoretically possible to share the event loop from within the ffi library and make Workerman utilize it? Similar to when Workerman can optionally utilize Swoole's loop?! 🤔

from webman.

walkor avatar walkor commented on May 25, 2024

Theoretically, it is possible.

from webman.

cayolblake avatar cayolblake commented on May 25, 2024

What's required to make a Workerman compliant event loop?

from webman.

walkor avatar walkor commented on May 25, 2024

Implement EventInterface see https://github.com/walkor/workerman/blob/master/src/Events/Event.php.

from webman.

cayolblake avatar cayolblake commented on May 25, 2024

@walkor since I'm talking about a C/FFI event loop, any idea or practical example you can provide me to help have an idea how to start?

from webman.

walkor avatar walkor commented on May 25, 2024

Sorry, I don't have C/FFI event loop related experience and can't help you.

from webman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.