https://github.com/x42en/phpsession
Manage PHP $_SESSION var stored in JSON with node.js, using memcached server
https://github.com/x42en/phpsession
coffeescript memcache nodejs npm php
Last synced: 5 months ago
JSON representation
Manage PHP $_SESSION var stored in JSON with node.js, using memcached server
- Host: GitHub
- URL: https://github.com/x42en/phpsession
- Owner: x42en
- License: apache-2.0
- Created: 2015-04-24T00:56:28.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-03-17T01:26:44.000Z (almost 9 years ago)
- Last Synced: 2025-03-25T10:43:05.854Z (11 months ago)
- Topics: coffeescript, memcache, nodejs, npm, php
- Language: CoffeeScript
- Size: 20.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHPSession
[](https://nodei.co/npm/phpsession/)
[](https://www.npmjs.org/package/phpsession)
[](https://www.npmjs.org/package/phpsession)
[](https://travis-ci.org/x42en/PHPSession)
[](https://www.npmjs.org/package/phpsession)
[](https://snyk.io/test/github/x42en/phpsession)
Simple module to manipulate PHP session vars ($_SESSION) stored in JSON, using *memcached*
>CAREFUL: this is NEW version of memcache !
**Important:** This package is **NOT** backward compatible with 0.1.x versions... Be careful if you update your npm project...
## Install
Install with npm:
```sh
npm install phpsession
```
## Basic Usage
Require the module:
```coffeescript
PHPSESSION = require 'phpsession'
```
Instantiate:
```coffeescript
sess = new PHPSESSION()
```
## Method usage:
### Connect to server:
```coffeescript
sess.connect
host: 127.0.0.1 # Default value
port: 11211 # Default value
```
### Check server is connected
```coffeescript
if sess.isConnected()
console.log 'All right !!'
```
### Retrieve $_SESSION value:
```coffeescript
sess.get
id: '9eir0ul21knvmlhu0a4kleh8j1'
,(data) -> console.log data
```
### Define a $_SESSION var:
```coffeescript
sess.set
id: '9eir0ul21knvmlhu0a4kleh8j1'
data: { 'hello': 'world' }
lifetime: 1440
```
### Replace a $_SESSION var:
```coffeescript
sess.replace
id: '9eir0ul21knvmlhu0a4kleh8j1'
data: { 'hello': 'world' }
lifetime: 1440
```
### Refresh a $_SESSION:
```coffeescript
sess.refresh
id: '9eir0ul21knvmlhu0a4kleh8j1'
lifetime: 1440
```
### Update specific $_SESSION key:
```coffeescript
sess.update
id: '9eir0ul21knvmlhu0a4kleh8j1'
key: 'hello'
value: 'better world'
lifetime: 1440
```
### Delete $_SESSION id:
```coffeescript
sess.delete
id: '9eir0ul21knvmlhu0a4kleh8j1'
```
## Extended usage
All methods supports callback parameters:
```coffeescript
sess.set
id: '9eir0ul21knvmlhu0a4kleh8j1'
data: { 'hello': 'better world' }
, (res) ->
console.log "Received: #{res}"
# Do something with result...
```
## Run tests
You can run unit-tests using mocha with:
```sh
npm test
```