Proof of concept questions

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

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 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?


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:

Quoted text here. Click to load it

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 /

Re: Proof of concept questions

Quoted text here. Click to load it

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.

Re: Proof of concept questions

Quoted text here. Click to load it

 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.

< Space: disk usage analysis tool

Re: Proof of concept questions

 .oO(Andy Hassall)

Quoted text here. Click to load it

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.


Re: Proof of concept questions

Quoted text here. Click to load it
better off
out how
Quoted text here. Click to load it

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.

Re: Proof of concept questions

nop90 wrote:

Quoted text here. Click to load it

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.
Quoted text here. Click to load it

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


Re: Proof of concept questions

nop90 wrote:
Quoted text here. Click to load it

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

Check the comments on <
to find examples of this.

Quoted text here. Click to load it

app-1 should be able to receive signals; you can send signals to app-1
from webpages with <
(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/ Your webpage would read
that pid and kill the process with that pid.

Re: Proof of concept questions

Quoted text here. Click to load it

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

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?

Re: Proof of concept questions

Quoted text here. Click to load it

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
(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.

--                     Custom web programming
guhzo_42@lnubb.pbz (rot13)                User Management Solutions

Re: Proof of concept questions

Quoted text here. Click to load it
You can use set_time_limit(); increase the maximum the maximum execution

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


Quoted text here. Click to load it

Site Timeline