By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

Proof of concept questions

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
nop90 wrote:

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.

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.
The applications are simple,

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

C.
Jul 17 '05 #2

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


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/
Jul 17 '05 #3

P: n/a
Alan Little <al**@n-o-s-p-a-m-phorm.com> wrote in
news:Xn**************************@216.196.97.131:
You're better off running it from a cron job.


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.

Jul 17 '05 #4

P: n/a
On Tue, 21 Dec 2004 14:28:31 GMT, nop90 <bj**********@yahoo.com> wrote:
Alan Little <al**@n-o-s-p-a-m-phorm.com> wrote in
news:Xn**************************@216.196.97.13 1:
You're better off running it from a cron job.


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.


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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5

P: n/a
.oO(Andy Hassall)
And if it's not
your own server, your hosting company may not allow long-running processes.


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
Jul 17 '05 #6

P: n/a
nop90 wrote:
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.
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.

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

Now stop app-1.


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.

Jul 17 '05 #7

P: n/a
"nop90" <bj**********@yahoo.com> wrote in message
news:Xn*************************@64.164.98.29...
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?


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?
Jul 17 '05 #8

P: n/a
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:e6********************************@4ax.com...
On Tue, 21 Dec 2004 14:28:31 GMT, nop90 <bj**********@yahoo.com> wrote:
Alan Little <al**@n-o-s-p-a-m-phorm.com> wrote in
news:Xn**************************@216.196.97.13 1:
You're better off running it from a cron job.
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.


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.


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.
Jul 17 '05 #9

P: n/a
nop90 <bj**********@yahoo.com> wrote:
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?


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
gu******@lnubb.pbz (rot13) User Management Solutions
Jul 17 '05 #10

P: n/a
> 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


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
gu******@lnubb.pbz (rot13) User Management Solutions

Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.