All Projects → pmmp → pthreads

pmmp / pthreads

Licence: other
Fork of https://github.com/krakjoe/pthreads with various improvements, including PHP 7.4+ support

Programming Languages

c
50402 projects - #5 most used programming language
PHP
23972 projects - #3 most used programming language
M4
1887 projects

Labels

Projects that are alternatives of or similar to pthreads

session
Aplus Framework Session Library
Stars: ✭ 170 (+277.78%)
Mutual labels:  php8
doclite
PHP NoSQL database and document store
Stars: ✭ 57 (+26.67%)
Mutual labels:  php8
php-currency-api
Standardized wrapper for popular currency rate APIs. Currently supports FixerIO, CurrencyLayer, Open Exchange Rates and Exchange Rates API.
Stars: ✭ 17 (-62.22%)
Mutual labels:  php8
pagination
Aplus Framework Pagination Library
Stars: ✭ 167 (+271.11%)
Mutual labels:  php8
docker-nginx-php
Nginx PHP for Docker
Stars: ✭ 121 (+168.89%)
Mutual labels:  php8
alpine-php-fpm
Lightweight and optimised PHP-FPM (PHP 7.4, 8.0, 8.1) Docker images with essential extensions on top of latest Alpine Linux.
Stars: ✭ 53 (+17.78%)
Mutual labels:  php8
static-php-cli
Build single static PHP binary in linux, build with PHP project together, with Swoole and other popular extensions included.
Stars: ✭ 129 (+186.67%)
Mutual labels:  php8
autoload
Aplus Framework Autoload Library
Stars: ✭ 18 (-60%)
Mutual labels:  php8
php-builder
🐘 Build PHP 8.0 and newer
Stars: ✭ 57 (+26.67%)
Mutual labels:  php8
AuroraCMS
The Australian Open Source Content Management System
Stars: ✭ 13 (-71.11%)
Mutual labels:  php8
routing
Aplus Framework Routing Library
Stars: ✭ 186 (+313.33%)
Mutual labels:  php8
FoxPHP
一个轻量级的Nginx+PHP8本地开发环境
Stars: ✭ 8 (-82.22%)
Mutual labels:  php8
CryptoManana
An Advanced PHP Cryptography Framework
Stars: ✭ 15 (-66.67%)
Mutual labels:  php8
amp-converter
A PHP library to convert HTML articles, blog posts or similar content to AMP (Accelerated Mobile Pages).
Stars: ✭ 59 (+31.11%)
Mutual labels:  php8
php8-xdebug
PHP 8.0 for development and production usage. With nginx, brotli, xdebug, JIT and more...
Stars: ✭ 17 (-62.22%)
Mutual labels:  php8
Stratum-Panel
Stratum aims to be a scalable, reliable panel better than most solutions on the market made for selling virtual machines. It works by utilizing Proxmox's API to automatically manage/deploy virtual machines. Stratum is made in Laravel.
Stars: ✭ 26 (-42.22%)
Mutual labels:  php8
framework
Aplus Full-Stack Framework
Stars: ✭ 172 (+282.22%)
Mutual labels:  php8
php-simple-benchmark-script
Очень простой скрипт тестирования быстродействия PHP | Very simple script for testing of PHP operations speed (rusoft repo mirror)
Stars: ✭ 50 (+11.11%)
Mutual labels:  php8
SPL
[deprecated] Miscellaneous PHP library files required by PocketMine-MP and related projects
Stars: ✭ 13 (-71.11%)
Mutual labels:  php8
app
Aplus Framework App Project
Stars: ✭ 338 (+651.11%)
Mutual labels:  php8

Threading for PHP - Share Nothing, Do Everything :)

Build Status Build status

This project provides multi-threading that is compatible with PHP based on Posix Threads.

This is a fork of the now-abandoned krakjoe/pthreads extension.

Focus

This fork is used in production on thousands of PocketMine-MP servers worldwide. Therefore, the focus is on performance and stability.

Changes compared to the original

  • PHP 7.4 and 8.0 support
  • Many bug fixes which were never merged upstream
  • Performance improvements
  • Memory usage improvements
  • Integration with OPcache on PHP 7.4+ (pthreads leverages opcache SHM to reuse classes and functions, saving lots of memory)
  • OPcache JIT support on PHP 8.0.2+

OPcache compatibility

Despite popular belief, OPcache is still useful in a CLI environment - as long as it's a threaded one :) Every thread in pthreads is like a web server "request", so while OPcache doesn't offer as big an advantage to an application using pthreads as it does to a web server, it's far from useless.

If you're using PHP 7.4+, using OPcache with pthreads is strongly recommended, as you'll get various benefits from doing so:

  • Reduced memory usage when the same class is used on several threads
  • Better performance of starting new threads when threads inherit classes and functions

Preloading classes and functions is also supported on PHP 7.4, which will make classes available to all threads without an autoloader.

OPcache isn't enabled in the CLI by default, so you'll need to add

opcache.enable_cli=1

to your php.ini file.

Why not drop pthreads and move on to something newer and easier to work with, like krakjoe/parallel?

  • We found parallel too limited for the use cases we needed it for. If it had some thread-safe class base like Threaded, it might be more usable.
  • It's possible to implement parallel's API using pthreads, but not the other way round.
  • parallel requires significant migration efforts for code using pthreads.

Some specific nitpicks which were deal-breakers for parallel usage in PocketMine-MP:

  • parallel has confusing and inconsistent behaviour surrounding object copying. While pthreads also has various inconsistencies and isn't exactly the easiest to understand thing in the world, its faults are well known (better the devil we know than the devil we don't).
  • parallel has uncontrollable behaviour around its object copying routine (it's not possible to customise copies or prevent copies from occurring).

Updating pthreads to PHP 7.4 allowed PocketMine-MP users to immediately gain the benefits of PHP 7.4 without needing to suffer API breaks that would affect plugins. In addition, PHP 7.4 introduced various new internal features which are highly beneficial specifically to pthreads, such as immutable classes and op_arrays.

Requirements

  • PHP 7.4+
  • ZTS Enabled ( Thread Safety )
  • Posix Threads Implementation (pthread-w32 / pthreads4w on Windows)

Testing has been carried out on x86, x64 and ARM, in general you just need a compiler and pthread.h

Unix-based Building from Source

Building pthreads from source is quite simple on Unix-based OSs. The instructions are as follows:

  • Clone this repository and checkout the release to use (or master for the latest updates)
  • cd pthreads
  • phpize
  • ./configure
  • make
  • make install (may need sudo)
  • Update your php.ini file to load the pthreads.so file using the extension directive

Windows Support

Yes !! Windows support is offered thanks to the pthread-w32 library.

Simple Windows Installation
  • Add pthreadVC2.dll (included with the Windows releases) to the same directory as php.exe eg. C:\xampp\php
  • Add php_pthreads.dll to PHP extension folder eg. C:\xampp\php\ext

Mac OSX Support

Yes !! Users of Mac will be glad to hear that pthreads is now tested on OSX as part of the development process.

Hello World

As is customary in our line of work:

<?php
$thread = new class extends Thread {
	public function run() {
		echo "Hello World\n";
	}
};

$thread->start() && $thread->join();
?>

SAPI Support

pthreads v3 is restricted to operating in CLI only: I have spent many years trying to explain that threads in a web server just don't make sense, after 1,111 commits to pthreads I have realised that, my advice is going unheeded.

So I'm promoting the advice to hard and fast fact: you can't use pthreads safely and sensibly anywhere but CLI.

Thanks for listening ;)

Documentation

Documentation can be found in the PHP manual: http://docs.php.net/manual/en/book.pthreads.php, and some examples can be found in the "examples" folder in the master repository.

Here are some links to articles I have prepared for users: everybody should read them before they do anything else:

Feedback

Please submit issues, and send your feedback and suggestions as often as you have them.

Reporting Bugs

If you believe you have found a bug in pthreads, please open an issue: Include in your report minimal, executable, reproducing code.

Minimal: reduce your problem to the smallest amount of code possible; This helps with hunting the bug, but also it helps with integration and regression testing once the bug is fixed.

Executable: include all the information required to execute the example code, code snippets are not helpful.

Reproducing: some bugs don't show themselves on every execution, that's fine, mention that in the report and give an idea of how often you encounter the bug.

It is impossible to help without reproducing code, bugs that are opened without reproducing code will be closed.

Please include version and operating system information in your report.

Developers

There is no defined API for you to create your own threads in your extensions, this project aims to provide Userland threading, it does not aim to provide a threading API for extension developers. I suggest you allow users to decide what they thread and keep your own extension focused on your functionality.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].