Download the PHP package ninsuo/php-shared-memory without Composer

On this page you can find all versions of the php package ninsuo/php-shared-memory. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-shared-memory

php-shared-memory

Share variables across multiple PHP apps

This class works like \stdClass, but one instance of SharedMemory can be used simultaneously in several PHP applications.

Because this class stores and restores its data every time a property is requested or set, data are always fresh between your applications. And because PHP has a great built-in advisory lock feature, there could be as many applications as you want, there is no concurrent access to the synchronization file.

Use cases

Long-running tasks : when there is a long-running task run in background from a web application, this is diffcult to display progression information. With SharedMemory, just set $shared->progress = x in your task, and echo $shared->progress in your web app.

Multi task : there is no built-in threads functions in PHP, so if we need to simulate threads, we execute several PHP tasks (forks, execs, ...), and keep control on resources and results. But from here, there is no way for all children processes to communicate each other. SharedMemory gives you a centralized data pool, where every processes can put about anything.

Installation

If you want a standalone file to manage your shared memory, you can look at the v1.5.0 release: https://github.com/ninsuo/php-shared-memory/releases/tag/v1.5.0

If you're building a real-life project, you'd better use Composer:

Install Composer

If you have curl, you can use:

curl -sS https://getcomposer.org/installer | php

Else, you can use the PHP method instead:

php -r "readfile('https://getcomposer.org/installer');" | php

Add the following to your composer.json:

Update

php composer.phar update

Usage

This class works the same way as stdClass, but you should give a storage in its constructor. This storage will be used to store and retrieve your data: use the same storage on several apps to get the same instance of a variable.

Or a complete working example:

How does it work ?

PHP has magic methods:

`__get($property)` let us implement the access of a $property on an object
`__set($property, $value)` let us implement the assignation of a $property on an object

PHP can serialize variables:

`serialize($variable)` returns a string representation of the variable
`unserialize($string)` returns back a variable from a string

PHP can handle files, with concurrent-access management:

`fopen($file, 'c+')` opens a file with advisory lock options enabled (allow you to use flock)
`flock($descriptor, LOCK_SH)` takes a shared lock (for reading)
`flock($descriptor, LOCK_EX)` takes an exclusive lock (for writting)

So, SharedMemory and StorageFile are working this way:

Optimizations

Of course, if you have 150 processes working on the same file at the same time, your hard drive will slow down your processes. To handle this issue, if you're on a Linux system, you can create a filesystem partition in RAM. Writing into a file stored in RAM will be about as quick as writing in memory.

As root, type the following commands:


All versions of php-shared-memory with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ninsuo/php-shared-memory contains the following files

Loading the files please wait ....