Re: [PHP] daemon without pcntl_fork

2009-08-22 Thread Jim Lucas

Lars Torben Wilson wrote:

2009/8/20 Jim Lucas :

Lars Torben Wilson wrote:

2009/8/19 Per Jessen :

Jim Lucas wrote:

[snip]


I probably wouldn't have chosen PHP for the first one, but there's no
reason it shouldn't work.  For the second one, did you mean to
write "serial port"?  That's a bit of a different animal, I'm not sure
how far you'll get with php.


Here is what I have come up with so far.  Looks to satisfying my
needs:

tms_daemon

[snip]

# END OF SCRIPT

Looks good to me. It'll certainly do the job.


/Per

I agree with Per on all points--I probably wouldn't choose PHP as a
first choice for the first task, but the startup script you have shown
looks like a bog-standard startup script and should serve you well. I
haven't really gone over it with a fine-toothed comb though. Typos
etc. are still up to to you. :) Of course, the whole thing depends on
how tms_daemon behaves, but the startup script looks OK.

Can you explain in a bit more detail exactly what the second part (the
serial-network data logger) needs to do? I've written similar daemons
in C but not PHP--when I've needed to get something like that going
with a PHP script, I've used ser2net (which I linked to in an earlier
post) and been quite happy. Maybe you don't even have to do the hard
work yourself (or buy extra hardware to do it for you).


Cheers,

Torben


As for the second project, I asked about it in the previous thread about
the SMDR/CDR processor.

http://www.nabble.com/SMDR-CDR-daemon-processor-td25014822.html


Sorry, missed that thread.


Basically, I need to have a process that collects data via serial
(USB|RS323), connects to a remote port, or listens and receives data
from the PBX pushing it.

The most common is the RS232 serial connection.  Thats why I need to be
able to listen on the local RS232 port for data coming from the PBX system.

What I have built so far can connect to a remote machine, via a TCP/IP
connection, and wait for data to be push out the specified TCP port.

I haven't done it yet, but I know that I can easily build, using a
different project as a base, the version that would connect to a local
TCP/IP IP:PORT and wait for a PBX to send the data to that IP:PORT.

After the data has been received, the process flow will be the same with
all three methods.  Parse it, sanitize it, store it.

Hopefully that explains a little more.

Jim


In short, are you looking for a program which listens on a serial port
and a network port at the same time, and places any data received from
either into a database?



No, I am looking to build and application that will have the option doing either of the three 
methods.  All at separate times.


It will be configured to work one phone system at a time.  It will either listen locally, connect 
remotely via TCP/IP, or open a COM port.  But, at this point, I don't see a need to have the ability 
to have it doing more then one method at a time.


Thanks



Regards,

Torben



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] daemon without pcntl_fork

2009-08-22 Thread Lars Torben Wilson
2009/8/20 Jim Lucas :
> Lars Torben Wilson wrote:
>> 2009/8/19 Per Jessen :
>>> Jim Lucas wrote:
>>
>> [snip]
>>
>>> I probably wouldn't have chosen PHP for the first one, but there's no
>>> reason it shouldn't work.  For the second one, did you mean to
>>> write "serial port"?  That's a bit of a different animal, I'm not sure
>>> how far you'll get with php.
>>>
 Here is what I have come up with so far.  Looks to satisfying my
 needs:

 tms_daemon
>>> [snip]
 # END OF SCRIPT
>>> Looks good to me. It'll certainly do the job.
>>>
>>>
>>> /Per
>>
>> I agree with Per on all points--I probably wouldn't choose PHP as a
>> first choice for the first task, but the startup script you have shown
>> looks like a bog-standard startup script and should serve you well. I
>> haven't really gone over it with a fine-toothed comb though. Typos
>> etc. are still up to to you. :) Of course, the whole thing depends on
>> how tms_daemon behaves, but the startup script looks OK.
>>
>> Can you explain in a bit more detail exactly what the second part (the
>> serial-network data logger) needs to do? I've written similar daemons
>> in C but not PHP--when I've needed to get something like that going
>> with a PHP script, I've used ser2net (which I linked to in an earlier
>> post) and been quite happy. Maybe you don't even have to do the hard
>> work yourself (or buy extra hardware to do it for you).
>>
>>
>> Cheers,
>>
>> Torben
>>
>
> As for the second project, I asked about it in the previous thread about
> the SMDR/CDR processor.
>
> http://www.nabble.com/SMDR-CDR-daemon-processor-td25014822.html

Sorry, missed that thread.

> Basically, I need to have a process that collects data via serial
> (USB|RS323), connects to a remote port, or listens and receives data
> from the PBX pushing it.
>
> The most common is the RS232 serial connection.  Thats why I need to be
> able to listen on the local RS232 port for data coming from the PBX system.
>
> What I have built so far can connect to a remote machine, via a TCP/IP
> connection, and wait for data to be push out the specified TCP port.
>
> I haven't done it yet, but I know that I can easily build, using a
> different project as a base, the version that would connect to a local
> TCP/IP IP:PORT and wait for a PBX to send the data to that IP:PORT.
>
> After the data has been received, the process flow will be the same with
> all three methods.  Parse it, sanitize it, store it.
>
> Hopefully that explains a little more.
>
> Jim

In short, are you looking for a program which listens on a serial port
and a network port at the same time, and places any data received from
either into a database?


Regards,

Torben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] daemon without pcntl_fork

2009-08-20 Thread Jim Lucas
Lars Torben Wilson wrote:
> 2009/8/19 Per Jessen :
>> Jim Lucas wrote:
> 
> [snip]
> 
>> I probably wouldn't have chosen PHP for the first one, but there's no
>> reason it shouldn't work.  For the second one, did you mean to
>> write "serial port"?  That's a bit of a different animal, I'm not sure
>> how far you'll get with php.
>>
>>> Here is what I have come up with so far.  Looks to satisfying my
>>> needs:
>>>
>>> tms_daemon
>> [snip]
>>> # END OF SCRIPT
>> Looks good to me. It'll certainly do the job.
>>
>>
>> /Per
> 
> I agree with Per on all points--I probably wouldn't choose PHP as a
> first choice for the first task, but the startup script you have shown
> looks like a bog-standard startup script and should serve you well. I
> haven't really gone over it with a fine-toothed comb though. Typos
> etc. are still up to to you. :) Of course, the whole thing depends on
> how tms_daemon behaves, but the startup script looks OK.
> 
> Can you explain in a bit more detail exactly what the second part (the
> serial-network data logger) needs to do? I've written similar daemons
> in C but not PHP--when I've needed to get something like that going
> with a PHP script, I've used ser2net (which I linked to in an earlier
> post) and been quite happy. Maybe you don't even have to do the hard
> work yourself (or buy extra hardware to do it for you).
> 
> 
> Cheers,
> 
> Torben
> 

As for the second project, I asked about it in the previous thread about
the SMDR/CDR processor.

http://www.nabble.com/SMDR-CDR-daemon-processor-td25014822.html

Basically, I need to have a process that collects data via serial
(USB|RS323), connects to a remote port, or listens and receives data
from the PBX pushing it.

The most common is the RS232 serial connection.  Thats why I need to be
able to listen on the local RS232 port for data coming from the PBX system.

What I have built so far can connect to a remote machine, via a TCP/IP
connection, and wait for data to be push out the specified TCP port.

I haven't done it yet, but I know that I can easily build, using a
different project as a base, the version that would connect to a local
TCP/IP IP:PORT and wait for a PBX to send the data to that IP:PORT.

After the data has been received, the process flow will be the same with
all three methods.  Parse it, sanitize it, store it.

Hopefully that explains a little more.

Jim


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] daemon without pcntl_fork

2009-08-19 Thread Lars Torben Wilson
2009/8/19 Per Jessen :
> Jim Lucas wrote:

[snip]

> I probably wouldn't have chosen PHP for the first one, but there's no
> reason it shouldn't work.  For the second one, did you mean to
> write "serial port"?  That's a bit of a different animal, I'm not sure
> how far you'll get with php.
>
>> Here is what I have come up with so far.  Looks to satisfying my
>> needs:
>>
>> tms_daemon
> [snip]
>> # END OF SCRIPT
>
> Looks good to me. It'll certainly do the job.
>
>
> /Per

I agree with Per on all points--I probably wouldn't choose PHP as a
first choice for the first task, but the startup script you have shown
looks like a bog-standard startup script and should serve you well. I
haven't really gone over it with a fine-toothed comb though. Typos
etc. are still up to to you. :) Of course, the whole thing depends on
how tms_daemon behaves, but the startup script looks OK.

Can you explain in a bit more detail exactly what the second part (the
serial-network data logger) needs to do? I've written similar daemons
in C but not PHP--when I've needed to get something like that going
with a PHP script, I've used ser2net (which I linked to in an earlier
post) and been quite happy. Maybe you don't even have to do the hard
work yourself (or buy extra hardware to do it for you).


Cheers,

Torben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] daemon without pcntl_fork

2009-08-19 Thread Per Jessen
Jim Lucas wrote:

> Currently, I have two different uses for this startup script and
> daemon/bg process.
> 
> One will deal with a master server for one of my games and the second
> will be for running a PBX SMDR/CDR capturing tool.
> 
> The first must be able to deal with multiple simultaneous connections
> where as the second simply need to listen on the local serial port,
> connect to a remote IP:PORT, or attach itself to a IP:PORT
> and wait for input from another machine to be sent to it.  Once it
> receives the data, it simply parses it, sanitizes it, and stores it.

I probably wouldn't have chosen PHP for the first one, but there's no
reason it shouldn't work.  For the second one, did you mean to
write "serial port"?  That's a bit of a different animal, I'm not sure
how far you'll get with php.

> Here is what I have come up with so far.  Looks to satisfying my
> needs:
> 
> tms_daemon
[snip]
> # END OF SCRIPT

Looks good to me. It'll certainly do the job.


/Per

-- 
Per Jessen, Zürich (22.5°C)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] daemon without pcntl_fork

2009-08-19 Thread Jim Lucas

Lars Torben Wilson wrote:

2009/8/18 Per Jessen :

Jim Lucas wrote:


Does anybody know how to use PHP as a daemon without the use of
pcntl_fork.


Sure. Just start it and leave it running.


I want to launch a daemon out of the /etc/rc.local when the system
starts.

Yep, I do that all the time.


Anybody have any idea on how to do this?

On an openSUSE system I would just use 'startproc', but elsewhere you
could use setsid or nohup.  I.e. create your CLI script with a
hash-bang, then start it

nohup 

Re: [PHP] daemon without pcntl_fork

2009-08-18 Thread Lars Torben Wilson
2009/8/18 Per Jessen :
> Lars Torben Wilson wrote:
>
>> Again, that's not a daemon. If it is sufficient to run a background
>> process then that's fine, but that doesn't make it a daemon (although
>> it shares some things in common with a daemon). The background process
>> still has a controlling terminal (even if input and output have been
>> redirected), and a fully-implemented daemon will typically perform
>> other tasks which make it a good system citizen, such as: becoming
>> session leader, chroot'ing to / so that the filesystem it was started
>> from can be unmounted if necessary, and so on.
>
> Torben, you're really just splitting hairs - the OP didn't ask for the
> definition of "daemon', he just wanted a script to run continually as
> if it was a daemon.  Besides, I did also suggest using either setsid or
> openSUSEs startproc.

Thank you for the lecture. Your opinion of my post on this is quite
beside the point. If Jim needs a daemon, then he should probably use a
daemon coded the best way possible. If not, then that's fine too. As
you correctly pointed out, there are ways to fake it. I simply feel
that Jim should be made aware of potential drawbacks. That's perhaps
splitting hairs--it's also being thorough. Clients don't tend to
appreciate being told that a lack of thoroughness arose from a fear of
splitting hairs.


Regards,

Torben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] daemon without pcntl_fork

2009-08-18 Thread Per Jessen
Lars Torben Wilson wrote:

> Again, that's not a daemon. If it is sufficient to run a background
> process then that's fine, but that doesn't make it a daemon (although
> it shares some things in common with a daemon). The background process
> still has a controlling terminal (even if input and output have been
> redirected), and a fully-implemented daemon will typically perform
> other tasks which make it a good system citizen, such as: becoming
> session leader, chroot'ing to / so that the filesystem it was started
> from can be unmounted if necessary, and so on.

Torben, you're really just splitting hairs - the OP didn't ask for the
definition of "daemon', he just wanted a script to run continually as
if it was a daemon.  Besides, I did also suggest using either setsid or
openSUSEs startproc. 


/Per

-- 
Per Jessen, Zürich (28.5°C)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] daemon without pcntl_fork

2009-08-18 Thread Lars Torben Wilson
2009/8/18 Per Jessen :
> Jim Lucas wrote:
>
>> Does anybody know how to use PHP as a daemon without the use of
>> pcntl_fork.
>>
>
> Sure. Just start it and leave it running.
>
>> I want to launch a daemon out of the /etc/rc.local when the system
>> starts.
>
> Yep, I do that all the time.
>
>> Anybody have any idea on how to do this?
>
> On an openSUSE system I would just use 'startproc', but elsewhere you
> could use setsid or nohup.  I.e. create your CLI script with a
> hash-bang, then start it
>
> nohup 

Re: [PHP] daemon without pcntl_fork

2009-08-18 Thread Per Jessen
Jim Lucas wrote:

> Does anybody know how to use PHP as a daemon without the use of
> pcntl_fork.
> 

Sure. Just start it and leave it running. 

> I want to launch a daemon out of the /etc/rc.local when the system
> starts.

Yep, I do that all the time.

> Anybody have any idea on how to do this?

On an openSUSE system I would just use 'startproc', but elsewhere you
could use setsid or nohup.  I.e. create your CLI script with a
hash-bang, then start it 

nohup 

Re: [PHP] daemon without pcntl_fork

2009-08-17 Thread Lars Torben Wilson
2009/8/17 Jim Lucas :
> I want this to be a system that works out of the box.  For the most part.
>
> I am expecting to have phone system vendors and low-level IT personal trying
> to install this thing.
>
> I don't want to have to field tons of questions on "How do I compile this
> p&#*(_fork thing into PHP?
>
> Anyways, could I compile a customer build of the php cli and include that
> into my package?

Certainly! You haven't mentioned how you intend to package it though,
so that "Certainly!" does come with some caveats. But including pcntl
is no different from including any other extension--in fact, the
chances of the target system being able to deal with it are greater,
if anything. If you compile it in, it'll be there. However, if it's
going to be limited to the point that you're including binaries only
for a specific platform, then A) compiling it in is no big deal, and
B) perhaps you should be looking at how you're packaging the thing.

> Would things be statically links to the binary.  ie every thing it needed
> would be built into it. Or would I have to rip out as much as possible to
> make sure that it was compatible with a persons system?

Not sure what you mean by that, but if the target audience isn't
competent to deal with this, then your support calls are going to hurt
either way. :) Which is why I said perhaps you should be looking at
how you're packaging it. Anything you compile on one system is going
to require some forethought in order to make it broadly applicable on
other systems, but any relevant system should be able to handle the
basics such as process control.


Regards,

Torben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] daemon without pcntl_fork

2009-08-17 Thread Jim Lucas

Lars Torben Wilson wrote:

2009/8/17 Jim Lucas :

Does anybody know how to use PHP as a daemon without the use of pcntl_fork.

http://php.net/pcntl_fork


Hi Jim,

AFAIK you can't. Read on. . .


I don't want to have to have a person have a special/custom compilation
of PHP just to run a simple daemon.

My system:  OpenBSD 4.5 w/PHP v5.2.8

I want to launch a daemon out of the /etc/rc.local when the system starts.

My goal is to write a script that will be launched from /etc/rc.local
when a system boots.  I want it to be detached from any shell or ssh
login that I launch it from also.

Anybody have any idea on how to do this?

I have played with system() and it does work.


What you've done below is not create a daemon, but a background
process. It's still attached to the shell you started it in (try
killing the shell you started it from and see what happens). There are
other differences too. IMHO the approach you've used here does have
its uses, and I've used it (and still do) when it's appropriate, but
when what you need is a daemon, then faking it with a background
process just isn't enough.

Compiling in pcntl isn't really that big of a deal--depending on
exactly what you're trying to accomplish. Why is it a problem in your
case? Perhaps there is another way around the issue which has a
cleaner solution. For the cases I've run into, pcntl has worked
admirably.



I want this to be a system that works out of the box.  For the most part.

I am expecting to have phone system vendors and low-level IT personal trying to 
install this thing.

I don't want to have to field tons of questions on "How do I compile this 
p&#*(_fork thing into PHP?

Anyways, could I compile a customer build of the php cli and include that into 
my package?

Would things be statically links to the binary.  ie every thing it needed would be built into it. 
Or would I have to rip out as much as possible to make sure that it was compatible with a persons 
system?


Thanks for the input!


test.php:
/dev/null &');
echo 'Done';
?>

test_cli.php


The above, when called, launches test_cli.php and detaches it from the
cli and returns to the system prompt


Well, after writing all this out, I think I have answered by own question.

If anybody else has a better suggestion, I am all ears.

If you have a better way of doing it, please share.

Also, a second piece to this would be a script to manage
(start/stop/restart/etc...) the parent daemon.

Something along the line of apachectl or similar.

TIA!

Update to the last email also.

I found another device that does RS232 to ethernet:

http://www.hw-group.com/products/portstore2/index_en.html

Anybody work with one of these?


Not me. But I've solved similar problems using ser2net (see
http://sourceforge.net/projects/ser2net/ ), sometimes running it on a
small embedded Linux device. Works great and I don't have to pay
someone else to sell me a free solution. :) But again, it depends on
your actual situation and what problem you're trying to solve. On the
face of it the device you linked looks OK. (I'm afraid I missed your
earlier post on the topic.)


Again, thanks!

Jim Lucas


I'm not trying to shoot down any ideas you've had or anything, just
wondering what's so bad about compiling pcntl in and hoping that maybe
you can save a few bucks on the serial-to-network problem by making
use of existing free software. Post more about what your situation is
and who knows? Maybe a fakey-daemon using background processes and a
proprietary serial-to-network device really is the best answer for
you.

Either way, good luck!


Regards,

Torben




--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] daemon without pcntl_fork

2009-08-17 Thread Lars Torben Wilson
2009/8/17 Jim Lucas :
> Does anybody know how to use PHP as a daemon without the use of pcntl_fork.
>
> http://php.net/pcntl_fork

Hi Jim,

AFAIK you can't. Read on. . .

> I don't want to have to have a person have a special/custom compilation
> of PHP just to run a simple daemon.
>
> My system:  OpenBSD 4.5 w/PHP v5.2.8
>
> I want to launch a daemon out of the /etc/rc.local when the system starts.
>
> My goal is to write a script that will be launched from /etc/rc.local
> when a system boots.  I want it to be detached from any shell or ssh
> login that I launch it from also.
>
> Anybody have any idea on how to do this?
>
> I have played with system() and it does work.

What you've done below is not create a daemon, but a background
process. It's still attached to the shell you started it in (try
killing the shell you started it from and see what happens). There are
other differences too. IMHO the approach you've used here does have
its uses, and I've used it (and still do) when it's appropriate, but
when what you need is a daemon, then faking it with a background
process just isn't enough.

Compiling in pcntl isn't really that big of a deal--depending on
exactly what you're trying to accomplish. Why is it a problem in your
case? Perhaps there is another way around the issue which has a
cleaner solution. For the cases I've run into, pcntl has worked
admirably.

> test.php:
>  echo 'Starting';
> system('/usr/local/bin/php test_cli.php >/dev/null &');
> echo 'Done';
> ?>
>
> test_cli.php
> 
> for( $i=1; $i<=10; $i++ ) {
>        echo "Echo {$i}\n";
>        sleep(1);
> }
>
> echo 'Done';
>
> ?>
>
> The above, when called, launches test_cli.php and detaches it from the
> cli and returns to the system prompt
>
>
> Well, after writing all this out, I think I have answered by own question.
>
> If anybody else has a better suggestion, I am all ears.
>
> If you have a better way of doing it, please share.
>
> Also, a second piece to this would be a script to manage
> (start/stop/restart/etc...) the parent daemon.
>
> Something along the line of apachectl or similar.
>
> TIA!
>
> Update to the last email also.
>
> I found another device that does RS232 to ethernet:
>
> http://www.hw-group.com/products/portstore2/index_en.html
>
> Anybody work with one of these?

Not me. But I've solved similar problems using ser2net (see
http://sourceforge.net/projects/ser2net/ ), sometimes running it on a
small embedded Linux device. Works great and I don't have to pay
someone else to sell me a free solution. :) But again, it depends on
your actual situation and what problem you're trying to solve. On the
face of it the device you linked looks OK. (I'm afraid I missed your
earlier post on the topic.)

> Again, thanks!
>
> Jim Lucas

I'm not trying to shoot down any ideas you've had or anything, just
wondering what's so bad about compiling pcntl in and hoping that maybe
you can save a few bucks on the serial-to-network problem by making
use of existing free software. Post more about what your situation is
and who knows? Maybe a fakey-daemon using background processes and a
proprietary serial-to-network device really is the best answer for
you.

Either way, good luck!


Regards,

Torben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] daemon without pcntl_fork

2009-08-17 Thread Jim Lucas
Does anybody know how to use PHP as a daemon without the use of pcntl_fork.

http://php.net/pcntl_fork

I don't want to have to have a person have a special/custom compilation
of PHP just to run a simple daemon.

My system:  OpenBSD 4.5 w/PHP v5.2.8

I want to launch a daemon out of the /etc/rc.local when the system starts.

My goal is to write a script that will be launched from /etc/rc.local
when a system boots.  I want it to be detached from any shell or ssh
login that I launch it from also.

Anybody have any idea on how to do this?

I have played with system() and it does work.

test.php:
/dev/null &');
echo 'Done';
?>

test_cli.php


The above, when called, launches test_cli.php and detaches it from the
cli and returns to the system prompt


Well, after writing all this out, I think I have answered by own question.

If anybody else has a better suggestion, I am all ears.

If you have a better way of doing it, please share.

Also, a second piece to this would be a script to manage
(start/stop/restart/etc...) the parent daemon.

Something along the line of apachectl or similar.

TIA!

Update to the last email also.

I found another device that does RS232 to ethernet:

http://www.hw-group.com/products/portstore2/index_en.html

Anybody work with one of these?

Again, thanks!

Jim Lucas


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php