PHP Classes

File: docs/MesQ.md

Recommend this page to a friend!
  Classes of Kjell-Inge Gustafsson   MesQ PHP Queue Management System   docs/MesQ.md   Download  
File: docs/MesQ.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: MesQ PHP Queue Management System
Queue and pull messages store in directory files
Author: By
Last change: 1.05
Date: 3 years ago
Size: 3,678 bytes
 

Contents

Class file image Download

[comment]: # (This file is part of MesQ, PHP lite disk based message queue manager. Copyright 2021 Kjell-Inge Gustafsson, kigkonsult, All rights reserved, licence LGPLv3)

MesQ methods

Construct, factory and singleton methods

The constructor method is private

factory( queueName [, directory ] )
  • MesQ (static) factory method
  • 
    
  • 
    
  • Return _MesQ_ class instance
  • Throws _InvalidArgumentException_
  • _static_
singleton( queueName [, directory ] )
  • MesQ (static) singleton getInstance method, based on the unique _queueName_/_directory_
  • 
    
  • 
    
  • Return _MesQ_ class instance
  • Throws _InvalidArgumentException_
  • _static_

Config methods

getConfig( [ key ] )
  • Review MesQinterface.php for details
  • 
    
  • Return _array_ config key/value pairs or key _int_|_string_ value
configToString()
  • Review MesQinterface.php for details
  • Return _string_, nicely rendered config key/value pairs

Add messages to queue, logic methods

qPush( config, message [, priority ] )
  • One-liner, insert single message to queue (incl. the factory method)
  • 
    
  • 
    
  • _static_
  • Throws _InvalidArgumentException_, _RuntimeException_
push( message [, priority ] )
  • 
    
  • Throws _InvalidArgumentException_, _RuntimeException_
insert( message [, priority ] )
  • _push_ method alias

Fetch messages from queue, logic methods

messageExist( [ priority ] )
  • 
    
  • Return _bool_ true if message(s) exists, false not
  • Throws _RuntimeException_
getMessage(  [ priority ] )
  • For queue type PRIO, messages are returned in priority order, also without arg
  • 
    
  • Return _mixed_, message or _bool_ false if no message found (i.e. end-of-queue)
  • Throws _RuntimeException_
pull(  [ priority ] )
  • _getMessage_ method alias

Queue size methods

getQueueSize(  [ priority ] )
  • 
    
  • Return _int_ the queue size in number of messages (now), _bool_ false on error
size(  [ priority ] )
  • _getQueueSize_ method alias
getDirectorySize()
  • Return _int_, the directory size in bytes (now)

Misc

If the 'Fetch messages from queue'-PHP script is placeced in cron, you should implement some file-locking logic to prevent concurrent processes running. Ex: https://www.php.net/manual/en/function.flock.php#117162

You should always set the 'RETURNCHUNKSIZE' config key otherwise the 'Fetch messages from queue'-PHP script may continue forever i.e. until PHP exec script timeout.

Using more complex class instances (with ex Closure) as message may throw a serialize Exception.

Go to [README]

[README]:../README.md