Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 11:08 AM
nop90
Guest
 
Posts: n/a
Default Proof of concept questions

Proof of concept: Currently I have a web hosting service and it does
support php.

Can the following be done in php? Explanations or examples would be
appreciated.

Create 2 applications, app-1 and app-2

app-1 loops continuosly. Every 1 second the application writes the time of
day to a file.

app-2 reads the file and displays it on a webpage.

I want to start app-1 from a webpage, then close the webpage. App-1
continues to log the time of day to the file.

At some later point in time...run app-2. It opens the file and displays
the contents.

Now stop app-1.

The applications are simple, but they answer a couple of basic questions I
need to know about php before I jump into developing an application. I
assume this might be easier if I have a decicated server instead of web
hosting only?

TIA
  #2  
Old July 17th, 2005, 11:08 AM
Colin McKinnon
Guest
 
Posts: n/a
Default Re: Proof of concept questions

nop90 wrote:
[color=blue]
>
> Can the following be done in php? Explanations or examples would be
> appreciated.
>
> Create 2 applications, app-1 and app-2
>
> app-1 loops continuosly. Every 1 second the application writes the time of
> day to a file.
>[/color]

Yes - this is posible with PHP, although you ISP may not have setup the
machine to allow this (PHP is typically used for generating web pages - a
new process/thread is started for each web page) - long running processes
in this context are a bad thing and both webservers and PHP have mechanisms
to prevent them.
[color=blue]
> The applications are simple,[/color]


I'm so not going to rise to that one.

C.
  #3  
Old July 17th, 2005, 11:08 AM
Alan Little
Guest
 
Posts: n/a
Default Re: Proof of concept questions

Carved in mystic runes upon the very living rock, the last words of
nop90 of comp.lang.php make plain:
[color=blue]
> I want to start app-1 from a webpage, then close the webpage.[/color]

Even if your script doesn't time out (which it most likely will, depending
on your server setup), closing the web page will end its run.

You're better off running it from a cron job.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
  #4  
Old July 17th, 2005, 11:08 AM
nop90
Guest
 
Posts: n/a
Default Re: Proof of concept questions

Alan Little <alan@n-o-s-p-a-m-phorm.com> wrote in
news:Xns95C6598C16CE8alanphormcom@216.196.97.131:
[color=blue]
> You're better off running it from a cron job.
>[/color]

Can a cron job be created to run every second? When I looked at my web
host's info on how to create a cron job, I seem to remember 1 minute was
the smallest resolution.

  #5  
Old July 17th, 2005, 11:08 AM
Andy Hassall
Guest
 
Posts: n/a
Default Re: Proof of concept questions

On Tue, 21 Dec 2004 14:28:31 GMT, nop90 <bjones_calif@yahoo.com> wrote:
[color=blue]
>Alan Little <alan@n-o-s-p-a-m-phorm.com> wrote in
>news:Xns95C6598C16CE8alanphormcom@216.196.97.13 1:
>[color=green]
>> You're better off running it from a cron job.[/color]
>
>Can a cron job be created to run every second? When I looked at my web
>host's info on how to create a cron job, I seem to remember 1 minute was
>the smallest resolution.[/color]

It is. If you want things to run every second, then you're probably better off
setting it up as a daemon process, i.e. running continually, and have it manage
its own timing (e.g from PHP, by using microtime() and usleep() to work out how
long of the 1-second window it has left, and to go to sleep during that time).
Whether this would be appropriate to do in PHP given its relatively lazy
garbage collection is left as an exercise for the reader ;-) And if it's not
your own server, your hosting company may not allow long-running processes.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
  #6  
Old July 17th, 2005, 11:08 AM
Michael Fesser
Guest
 
Posts: n/a
Default Re: Proof of concept questions

.oO(Andy Hassall)
[color=blue]
>And if it's not
>your own server, your hosting company may not allow long-running processes.[/color]

Many shared hosts use the max_execution_time setting in the php.ini to
prevent scripts from running amok, others also restrict CPU time. It
will probably become difficult to set up a (kind of) daemon script on
such a system.

Micha
  #7  
Old July 17th, 2005, 11:08 AM
Dani CS
Guest
 
Posts: n/a
Default Re: Proof of concept questions

nop90 wrote:[color=blue]
> Proof of concept: Currently I have a web hosting service and it does
> support php.
>
> Can the following be done in php? Explanations or examples would be
> appreciated.
>
> Create 2 applications, app-1 and app-2
>
> app-1 loops continuosly. Every 1 second the application writes the time of
> day to a file.
>
> app-2 reads the file and displays it on a webpage.
>
> I want to start app-1 from a webpage, then close the webpage. App-1
> continues to log the time of day to the file.[/color]

The webpage should start a background process on the server. If you run
the process via 'nohup', it can keep running when the webpage has ended
execution.

Check the comments on <http://es2.php.net/manual/es/function.exec.php>
to find examples of this.
[color=blue]
>
> At some later point in time...run app-2. It opens the file and displays
> the contents.
>
> Now stop app-1.[/color]

app-1 should be able to receive signals; you can send signals to app-1
from webpages with <http://es.php.net/manual/es/function.posix-kill.php>
(examples included on that page).

You'll need to know the pid of app-1. One way of getting it is having
app-1 write its own pid to /var/run/app-1.pid. Your webpage would read
that pid and kill the process with that pid.



  #8  
Old July 17th, 2005, 11:09 AM
Chung Leong
Guest
 
Posts: n/a
Default Re: Proof of concept questions

"nop90" <bjones_calif@yahoo.com> wrote in message
news:Xns95C5D7F5D33A4bjonescalif@64.164.98.29...[color=blue]
> Proof of concept: Currently I have a web hosting service and it does
> support php.
>
> Can the following be done in php? Explanations or examples would be
> appreciated.
>
> Create 2 applications, app-1 and app-2
>
> app-1 loops continuosly. Every 1 second the application writes the time of
> day to a file.
>
> app-2 reads the file and displays it on a webpage.
>
> I want to start app-1 from a webpage, then close the webpage. App-1
> continues to log the time of day to the file.
>
> At some later point in time...run app-2. It opens the file and displays
> the contents.
>
> Now stop app-1.
>
> The applications are simple, but they answer a couple of basic questions I
> need to know about php before I jump into developing an application. I
> assume this might be easier if I have a decicated server instead of web
> hosting only?[/color]

For PHP 4, the answer is no, because the scripting engine is not every
aggressive in reclaiming unused memory. The memory footprint of a long
running script would grow steadily as it runs, until the process finally
sigfaults.

Most ISPs don't let you change the max execution time, so your script will
simply get cut off.

The concept you're trying to prove sounds kind of dumb to me. Since app-2
can fully extrapolate the data created by app-1, why border having it
running in the background?


  #9  
Old July 17th, 2005, 11:09 AM
Chung Leong
Guest
 
Posts: n/a
Default Re: Proof of concept questions

"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:e6egs0126qoao8edlvb2778q86vhmca3i4@4ax.com...[color=blue]
> On Tue, 21 Dec 2004 14:28:31 GMT, nop90 <bjones_calif@yahoo.com> wrote:
>[color=green]
> >Alan Little <alan@n-o-s-p-a-m-phorm.com> wrote in
> >news:Xns95C6598C16CE8alanphormcom@216.196.97.13 1:
> >[color=darkred]
> >> You're better off running it from a cron job.[/color]
> >
> >Can a cron job be created to run every second? When I looked at my web
> >host's info on how to create a cron job, I seem to remember 1 minute was
> >the smallest resolution.[/color]
>
> It is. If you want things to run every second, then you're probably[/color]
better off[color=blue]
> setting it up as a daemon process, i.e. running continually, and have it[/color]
manage[color=blue]
> its own timing (e.g from PHP, by using microtime() and usleep() to work[/color]
out how[color=blue]
> long of the 1-second window it has left, and to go to sleep during that[/color]
time).[color=blue]
> Whether this would be appropriate to do in PHP given its relatively lazy
> garbage collection is left as an exercise for the reader ;-) And if it's[/color]
not[color=blue]
> your own server, your hosting company may not allow long-running[/color]
processes.[color=blue]
>[/color]

You might be able to work around the long running script problem by having
the script make an HTTP request to itself. If user abort is turned off and
blocking is off for the file retrieval, then--at least in theory--the script
would spawn continually.


  #10  
Old July 17th, 2005, 11:39 AM
nospam@geniegate.com
Guest
 
Posts: n/a
Default Re: Proof of concept questions

nop90 <bjones_calif@yahoo.com> wrote:[color=blue]
> Proof of concept: Currently I have a web hosting service and it does
> support php.
>
> Can the following be done in php? Explanations or examples would be
> appreciated.
>
> Create 2 applications, app-1 and app-2
>
> app-1 loops continuosly. Every 1 second the application writes the time of
> day to a file.
>
> app-2 reads the file and displays it on a webpage.
>
> I want to start app-1 from a webpage, then close the webpage. App-1
> continues to log the time of day to the file.
>
> At some later point in time...run app-2. It opens the file and displays
> the contents.
>
> Now stop app-1.
>
> The applications are simple, but they answer a couple of basic questions I
> need to know about php before I jump into developing an application. I
> assume this might be easier if I have a decicated server instead of web
> hosting only?[/color]

Yes, it can be done in PHP, however, it can't really be done with web servers.

PHP has timeout functions and so-forth.

To actually do something like that in PHP, running in the context of a web server,
(Be prepared to have your ISP come down on you like a ton of bricks.. I'm not
actually suggesting this..)

Have app-1.php update the time stamp, sleep 1 second, contact *itself* over
HTTP, (ignore the results) disconnect. The timing won't be accurate, it won't
be reliable at all, but, it should stay running long enough for your sysadmin
to butcher you. :-)

A better solution, (if you don't mind it being longer than 1 second) is
something like cron. Why write the time to a file each second?

If you really need it written each second, you'll probably want a separate
process that runs as a daemon. ISP's tend to frown on that sort of thing.

Jamie
--
http://www.geniegate.com Custom web programming
guhzo_42@lnubb.pbz (rot13) User Management Solutions
  #11  
Old July 17th, 2005, 11:39 AM
Anders Holte
Guest
 
Posts: n/a
Default Re: Proof of concept questions

> PHP has timeout functions and so-forth.
You can use set_time_limit(); increase the maximum the maximum execution
time


But its probably better to use register_tick_function() and
unregister_tick_function():
void register_tick_function ( callback function [, mixed arg])
Registers the function named by function to be executed when a tick is
called.
Also, you may pass an array consisting of an object and a method as the
func.

/anders

[color=blue]
>
> To actually do something like that in PHP, running in the context of a web[/color]
server,[color=blue]
> (Be prepared to have your ISP come down on you like a ton of bricks.. I'm[/color]
not[color=blue]
> actually suggesting this..)
>
> Have app-1.php update the time stamp, sleep 1 second, contact *itself*[/color]
over[color=blue]
> HTTP, (ignore the results) disconnect. The timing won't be accurate, it[/color]
won't[color=blue]
> be reliable at all, but, it should stay running long enough for your[/color]
sysadmin[color=blue]
> to butcher you. :-)
>
> A better solution, (if you don't mind it being longer than 1 second) is
> something like cron. Why write the time to a file each second?
>
> If you really need it written each second, you'll probably want a separate
> process that runs as a daemon. ISP's tend to frown on that sort of thing.
>
> Jamie
> --
> http://www.geniegate.com Custom web programming
> guhzo_42@lnubb.pbz (rot13) User Management Solutions[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles