473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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
Jul 17 '05 #1
10 2306
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
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
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
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
.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
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
"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
"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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: cmc | last post by:
I need some clarification to help me understand the DB2 strucure more. The questions are about "implicit schema" 1. This is a very interest concpet that DB2 let every user to create new schema...
4
by: jm | last post by:
Consider: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwhenshouldiimplementinterfacesinmycomponent.asp // Code for the IAccount interface module. public...
0
by: duelearning | last post by:
I do not think that on the current market, or being developed, there is a real concept search tool. The key issue is that nobody has offered a satisfactory answer on what a concept is and its...
5
by: strutsng | last post by:
I want to clarify the concept of submitting the form to the web server. PHP is just an example here, it applies to any web programming languages. On page1.php, <form name="myform"...
20
by: Stan Sainte-Rose | last post by:
Hi, Sorry about this newbie question, but I have some questions about the MDI Concept. I have a MdiParent form that calls a Child Form (A). This Child Form (A) could call another Form (B). ...
2
by: Howard | last post by:
I need to write a web page that outputs a table from database. ( i want to write my own code, don't want to use the built-in control) I came up with two ways of doing this (i use c# 2.0) 1....
3
by: Antony Sequeira | last post by:
Hi I was trying to improve my understanding of generics. Reading the tutorial http://java.sun.com/docs/books/tutorial/extra/generics/methods.html I had a doubt and wanted to check it out. I...
2
by: Anton Vredegoor | last post by:
For the last few days I've been doodling with a script that provides a graphical interface to gnugo by using its GTP protocol. At the moment the script is *very* basic, in fact the only thing it...
4
by: Aries Sun | last post by:
The following code can be compiled without error: typedef char True; // sizeof(True) == 1 typedef struct { char a; } False; // sizeof(False) 1 //... template <typename TTrue isPtr( T * );...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.