phpsession

0.2.0 • Public • Published

PHPSession

NPM

Downloads per month npm version Build Status Dependencies

Simple module to manipulate PHP session vars ($_SESSION) stored in JSON, using memcached

CAREFUL: this is NEW version of memcache !

Install

Install with npm:

  npm install phpsession

Basic Usage

Require the module:

  PHPSESSION = require 'phpsession'

Instantiate with URL:

  sess = new PHPSESSION()

Method usage:

Connect to server:

  sess.connect
    host: 127.0.0.1  # Default value 
    port: 11211      # Default value 

Check server is connected

  if sess.isConnected()
    console.log 'All right !!'

Retrieve $_SESSION value:

  sess.get
    id: '9eir0ul21knvmlhu0a4kleh8j1'
    ,(data) -> console.log data

Define a $_SESSION var:

  sess.set
    id: '9eir0ul21knvmlhu0a4kleh8j1'
    data: { 'hello': 'world' }
    lifetime: 1440

Replace a $_SESSION var:

  sess.replace
    id: '9eir0ul21knvmlhu0a4kleh8j1'
    data: { 'hello': 'world' }
    lifetime: 1440

Refresh a $_SESSION:

  sess.refresh
    id: '9eir0ul21knvmlhu0a4kleh8j1'
    lifetime: 1440

Update specific $_SESSION key:

  sess.update
    id: '9eir0ul21knvmlhu0a4kleh8j1'
    key: 'hello'
    value: 'better world'
    lifetime: 1440

Delete $_SESSION id:

  sess.delete
    id: '9eir0ul21knvmlhu0a4kleh8j1'

Extended usage

All methods supports callback parameters:

  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:

  npm test

Package Sidebar

Install

npm i phpsession

Weekly Downloads

0

Version

0.2.0

License

Apache-2.0

Last publish

Collaborators

  • x62en