[ previous ] [ next ] [ threads ]
 
 From:  Paul Taylor <PaulTaylor at winn dash dixie dot com>
 To:  m0n0wall dash dev at lists dot m0n0 dot ch
 Subject:  RE: [m0n0wall-dev] The future - summary
 Date:  Fri, 14 Oct 2005 08:18:12 -0400
The Nanoweb developers have recently released nanoserv..  A socket toolkit
for PHP 5.1.  It's all OO and has support for multiplexing and forking
listeners...

This could just be the thing to use to write a core, but in PHP...

http://nanoserv.si.kz/

Here's the complete code (and output) for a simple shared object daemon with
forking support:

#!/root/tmp/php-src/sapi/cli/php
<?

/*

simple NS_Shared_Object and Nanoserv::Fork() example

this program outputs :

[14371] master process launched, forking
[14372] child process launched
[14371] setting value to 50
[14372] $so->value = 50
[14371] setting value to 100
[14372] $so->value = 100
[14371] setting value to 150
[14372] $so->value = 150
[14371] setting value to 200
[14372] $so->value = 200
[14371] setting value to 250
[14372] $so->value = 250
[14371] setting value to 300
[14372] $so->value = 300
[14371] setting value to 350
[14372] $so->value = 350
[14371] setting value to 400
[14372] $so->value = 400
[14371] setting value to 450
[14372] $so->value = 450
[14371] setting value to 500
[14372] $so->value = 500
[14371] 1100 IPC calls in 0.52 sec.

*/

require "nanoserv/nanoserv.php";

function pecho($s) {

    echo "[".posix_getpid()."] {$s}\n";

}

class foo {

    public $value = 0;

    public function set($v) {

        if (!($v % 50)) pecho("setting value to {$v}");

        $this->value = $v;

    }

    public function done($t) {

        pecho("1100 IPC calls in ".sprintf("%.2f", $t)." sec.");
        exit();

    }

}

$o = new foo();
$so = Nanoserv::New_Shared_Object($o);

pecho("master process launched, forking");

if (Nanoserv::Fork() > 0) Nanoserv::Run();

pecho("child process launched");

$t = microtime(true);

for ($a=1; $a<=500; $a++) {

    $so->set($a);

    $test = $so->value;

    if ($test != $a) pecho("ERROR: $test != $a");

    if (!($a % 50)) pecho('$so->value = '.$so->value);

}

$so->done(microtime(true) - $t);

?>


-----Original Message-----
From: Ulrik Lunddahl (PROconsult) [mailto:ul at proconsult dot dk] 
Sent: Friday, October 14, 2005 4:16 AM
To: m0n0wall dash dev at lists dot m0n0 dot ch
Subject: VS: [m0n0wall-dev] The future - summary 

Hello everyone!

> This has generated an outcry - many developers and even users don't
want to see
> m0n0wall using anything else but PHP. A few possible candidates for
the daemon
> were mentioned (Python, Ruby, Perl, ...), but apparently most people
would rather
> see things stay the way they are now. 

The problem as i see it (as a non programmer) is that PHP is not very
good at making a multithreaded deamon, but could a generic deamon not be
made in c++ (or something else good for that job), and then this deamon
spawns PHP scripts as it's "business logic".

It should be possible to make a very generic deamon having some sort of
queuing to keep everything i sync or not in synch, as requested by the
caller.

Best regards
Ulrik Lunddahl

---------------------------------------------------------------------
To unsubscribe, e-mail: m0n0wall dash dev dash unsubscribe at lists dot m0n0 dot ch
For additional commands, e-mail: m0n0wall dash dev dash help at lists dot m0n0 dot ch