• Index
  •  » Articles
  •  » Script Running Magic or saving objects in Word

Script Running Magic or saving objects in Word

Script Running Magic or saving objects in Word

Sessions support. Remote functions call. Saving variables global for all applications. Service for work with remote global objects.

Summary

Daemon and extension from API to PHP for it.

Developer: The Vulcan Logic Group.

Language: C

Purpose:

  • Sessions’ support;
  • Remote functions call;
  • Saving variables global for all applications;
  • Service for work with remote global objects.

Those who have wok with Application object in ASP (as for me, I haven’t) understand at once why they need SRM. In fact this thing is rather usual for ASP-programmers. And to those who haven’t worked with it I’ll try to explain. After two hours of SRM examining I’ve got a distinct association – “saving in Word”.

The analogy is really clear:

  • SRM saves objects ‘in cool’ but only the list of the already downloaded objects is available, not of all the available ones;
  • A remote object behaves the same as an object of this class declared in the script but its properties are invisible through var_dump (in-touch orientation);
  • An object is downloaded once by the first addressing and after that it begins its ‘remote existence’;
  • Properties and methods of an object are available to any script;
  • Along with objects SRM saves functions’ library and variables global for all scripts;
  • By means of SRM you may ‘cash’ connection with base (according to prior tests this results into considerable speeding-up) which is common for all the scripts

Variants of SRM usage:

  • users’ counter on the site;
  • cashing connections with base and frequently selected data from the base;
  • global site settings and templates;
  • common objects;
  • your variant…

Principle of SRM work:

  • Daemon reads srm.ini by starting, selects global functions from function_library and hears the port and socket indicated.
  • Client script addresses Daemon and it transmits the results of functions’ accomplishment. It’s namely the results’ transmission as far as functions like echo and print in the remote objects will display nothing (and they will display it into the Daemon’s log).

Objects of Banana child classes aren’t selected at once (1) but only after the first addressing. At this like in case with ordinary objects constructor is accomplished and so on. Further methods and properties of this object are available bur you won’t see them through var_dump as I’ve already said.

Scripts within which remote objects’ classes are declared have demand to naming: thus class Users should be contained within Users.banana.php and be a successor of Banana class. In the same way two strings are added in the end of the class (see example) which are necessary for remote object initialization.

Illustrative example: remote object class:

<? 

/* Club.banana.php */
/* Class Club */
Class Club extends Banana {
    var 
$members;

    function 
Club () {
        
$this->members="0";
    }

    function 
increase () {
        
$this->members++;
    }
}

$club = new Club();
$club->run();
?>

and client’s script:

<?
/* club.php */
    
$srm = new SRM ("/tmp/srm.socket"7777);

    
$t = new SRMApp ($srm,"Club");
    
$t->increase();
    echo 
$t->members."_n";

print_r($t);
?>

We put class into class_path, restart srmd and accomplish client’s script. On the output we get:

--=--
[number]
srmapp Object
(
    [conn_id] => Resource id #2
    [handle] => 1
)
--=--

The number will increase with each refresh. Of course, if you comment the string containing increase(), its value will remain the same. It looks like session; the main difference is that it is one for all.

A class like that may be attached to a forum; instead of simple conferring of ‘members’ property within constructor you may make a calculation of club members in the base (it’s no sense in making this selection on each page for each user); in case of adding or deletion you need to call corresponding class method – increase or decrease (increase at 1 and decrease correspondingly).

It seems to me to be rather convenient.

In the similar way class UsersOnSite is used. The principle is simple – to set up an original cookie for a person, to check if you posses it. If you don’t – it’s one person more, we check users’ timeouts, delete someone and so on.

It isn’t functioning by the time but is promised to appear in the nearest future:

  • saving and raising a dump between Daemon restarts;
  • remote objects cannot contain other remote objects and links to them;
  • many other useful features;
  • there is no version for Win (and it is unlikely to appear in the nearest time).

Also ISN’T supported (and unlikely to start doing it): PHP surroundings’ variables vision ($_SERVER, $_COOKIE etc.) in the remote objects because of technical reasons only – Daemon works without knowing anything about Apache.

I can also describe how I installed and set up Daemon and extension to PHP.

(1) if there are no any objects in dump after the last shutdown which it has recorded by the last logout (srmd dumps its ‘socket’ by logout and catches it by starting).

File srm.ini

#######
modules {
    path =  "/usr/local/srm/lib/";
    load    "auth";
    load    "http";
    load    "php4";
}

srm {
    sockname  =  "/tmp/srm.socket";
    port      =  7777;
    log_level =  100;
    logfile   =  "/var/log/srm";
}

store {
    application_items      = 2048;
    session_items          = 4096;
    application_lock_items = 1024;
    session_lock_items     = 1024;
    session_save_path      = "/var/state";
}

http {
    port =    7780;
}

banana {
    class_path       = "/usr/local/srm/banana/lib";
    function_library = "/usr/local/srm/banana/lib/library.php";
}
#######

Comments:

  • modules – loading SRM modules. For work with PHP a specifically composed PHP is needed (we’ll speak about this later). Without it modules auth & http function.
  • srm – I hope no comments are needed here.
  • store – settings of elements number saved in the memory and in sessions (SRM his got sessions of its own into which it records dump by shutdown and from where it reads by starting).
  • banana – settings of virtual class which is parent for all the classes that can be used with SRM.

 
  • Top