Coder Social home page Coder Social logo

fork-helper's Introduction

fork-helper

Simple class to fork processes in PHP and allow multi-threading.

Full documentation is available at https://duncan3dc.github.io/fork-helper/
PHPDoc API documentation is also available at https://duncan3dc.github.io/fork-helper/api/

release build coverage

Quick Example

Run some code asynchronously:

$fork = new \duncan3dc\Forker\Fork;

$fork->call(function () {
    for ($i = 1; $i <= 3; $i++) {
        echo "Process A - " . $i . "\n";
        sleep(1);
    }
});
$fork->call(function () {
    for ($i = 1; $i < 3; $i++) {
        echo "Process B - " . $i . "\n";
        sleep(1);
    }
});

sleep(1);
echo "Waiting for the threads to finish...\n";
$fork->wait();
echo "End\n";

Read more at https://duncan3dc.github.io/fork-helper/

Changelog

A Changelog has been available since version 2.0.0

Where to get help

Found a bug? Got a question? Just not sure how something works?
Please create an issue and I'll do my best to help out.
Alternatively you can catch me on Twitter

duncan3dc/fork-helper for enterprise

Available as part of the Tidelift Subscription

The maintainers of duncan3dc/fork-helper and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

fork-helper's People

Contributors

andreyslashman avatar duncan3dc avatar nightlinus avatar peter279k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fork-helper's Issues

Is it intended to be working with php-fpm?

I've heard/read different things about forking and php-fpm. Some said its only on working with the php apache module, some say its not working with php-fpm as well (stackoverflow), but it seams to be working with php-cli.
It would be cool, if you could point out the compatibility resp. the requirements for you helper to help ;-)

Thank you

[Question]

Hello there,

If I want to spawn 100 process then can I do following?

$fork = new \duncan3dc\Forker\Fork;
for( $i = 0 ; $i < 100 ; $i++)
{
$fork->call(function () {
    for ($i = 1; $i <= 3; $i++) {
        echo "Process A - " . $i . "\n";
        sleep(1);
    }
});
}

returning data using the same shared memory

Lets say there is a method called getResult(), returning all results of all call() methods or of individual processes - much like wait() can wait for all or a single one.

Would it be possible to return a simple string? This alone would be enough to send through serialized data. Maybe even change the call() method to use serialized data?

Thanks in advance.

Tagging new Version

Hello,

is it possible that you tag a new version. In the master branch is a fix that I would like to use. (#10 ) But there was no release since this PR was merged. It would help me a lot, since I only can use tagged versions in my environment and no dev-master.

Best Regards
Matthias

Warning: shmop_open(): unable to attach or create shared memory segment 'No space left on device'

After using this for a while I get this:
Warning: shmop_open(): unable to attach or create shared memory segment 'No space left on device'

When you call:
$ ipcs -m
You'll see a huge list of memory sections claimed by the forker.

I have a feeling that somehow the memory allocation is not cleared when something unexpected happens.

On MacOS this happens almost right away. And on Linux it takes many cycles before this occurs.

Help me to take a tag version 1.1.6

Dear Coder,
I like the project very well. It is very simple and useful, so I used it in my project with composer some days ago, but my php version is 5.6, and now I can not use your newest version. Can you help me make a tag version 1.1.6 at the commit:6eebe41566f7df96e9e411f0a509d7559360adf7, because I had used your function : getPIDs() ? if you do it ,I can use it now, because my project is only support php version 5.6, it can not work in your newest version. Thank you !

Error while sending QUERY packet

Hello there,

I am getting following error when I insert data into MySQL db.

Error while sending QUERY packet. PID=15521 with query: "INSERT INTO....

Do you know how to solve this issue?

SharedMemory::addException() is not atomic

If two forks are adding an exception at the same time, it's possible that they both read the current memory segment, then whichever thread writes second overwrites the first threads addition.

This isn't a major issue as at least an exception will always be reported when one has occurred, but if multiple occur we may miss the details of one (this is probably the cause of the occasional test failure we see on Travis

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.