PHP Classes

PHP Background Service Caller: Call background services running on socket servers

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 214 This week: 1All time: 8,319 This week: 560Up
Version License PHP version Categories
background-service 1.0.9BSD License5.4Networking, PHP 5
Description 

Author

This class can call background services running on socket servers.

It can connect to a server running on a TCP or UDP socket and sends requests to execute commands of services that run in the background.

The class can send a data paremeter to the server. For TCP requests, it can return the server response of the executed background service.

The class can also send requests to queue the execution of background services.

Picture of Thomas Björk
  Performance   Level  
Name: Thomas Björk <contact>
Classes: 11 packages by
Country: Sweden Sweden
Age: 55
All time rank: 1581 in Sweden Sweden
Week rank: 106 Up2 in Sweden Sweden Down
Innovation award
Innovation award
Nominee: 3x

Example

<?php
include_once('../bgcaller.php');
BackgroundServiceCaller::AssignIni('./example.ini');
header('Content-Type: application/javascript');
echo
BackgroundServiceCaller::TCPCall('coffee', file_get_contents('./example1.coffee'));


Details

BackgroundServiceCaller

This is a implementation in PHP for using BackgroundService written in javascript. (BackgroundService is designed to run in node.js).

Requirements

This class uses Fuse Array to handle the configuration. - PHPClasses - GitHub

The class uses JBackgroundService as the service manager. - JSClasses - GitHub

BackgroundServiceCaller

Functions

AssignIni($ini)

Loads the configuration into an ConfigArray (an extension of the class FuseArray)

ConvertCharset($data, $fromCharset, $toCharset)

Convert the data in the mixed-type variable $data from the charset defined in $fromCharset to the charset defined in $toCharset.

Init()

Initialize the object.

Returns a string containing the name of the class used in the call.

UDPCall($service, $data, $charset = false)

Create a call to the service defined in configuration. The call is made over a datagram socket.

There is no response to this call.

TCPCall($service, $data, $charset = false)

Create a call to the service defined in configuration and wait for the response. The call is made over a tcp socket.

TCPAddQueue($service, $data, $charset = false)

Make a call to the tcp service. But instead of waiting for the result the process returns directly and this function returns aa string that contains the job id for the process on the server.

TCPCheckQueue($id)

This function uses the job id created by TCPAddQueue to check the status for the job.

If the function returns: - 0 then the job has been created but not started. (This should not be possible since the status is changed from 0 to 1 before the TCPAddQueue returns.) - 1 then the job has been started. - 2 then the job is finished.

TCPGetQueue($id)

This function calls the job (defined by the id) and waits until the job is done (has the status 2).

Using multiple service hosts

The class is written to use a single configuration. The configuration can use several different services since it connects the name of a service to a section of the configuration.

But there is a way to use multiple configurations.

By extending the base class BackgroundServiceCaller it is possible to load one configuration for each extended class. This is since the internal system uses the name of the called class to store the configuration internally.

<?php
include('./bgcaller.php');
class DummyService1 extends BackgroundServiceCaller {}
class DummyService2 extends BackgroundServiceCaller {}
class DummyService3 extends BackgroundServiceCaller {}

BackgroundServiceCaller::AssignIni('./config0.ini');
DummyService1::AssignIni('./config1.ini');
DummyService2::AssignIni('./config2.ini');
DummyService3::AssignIni('./config3.ini');

// Now we can use four (4) different configurations.

  Files folder image Files  
File Role Description
Files folder imageexamples (4 files)
Plain text file bgcaller.php Class Class source
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file example.ini Data Auxiliary data
  Accessible without login Plain text file example1.coffee Data Auxiliary data
  Accessible without login Plain text file example1.php Example Example script
  Accessible without login Plain text file example2.php Example Example script

Downloadbackground-service-2024-01-09.zip 5KB
Downloadbackground-service-2024-01-09.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Fuse Array Download .zip .tar.gz Loads the configuration for the class Required
 Version Control Unique User Downloads Download Rankings  
 100%
Total:214
This week:1
All time:8,319
This week:560Up