Re: handing over data between two PHP connections

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2010-07-19 at 13:21 +0200, Tobias Mueller wrote:

> Am Sunday 18 July 2010 23:10:58 schrieb Floyd Resler:
> > On Jul 18, 2010, at 3:27 PM, tobias.mueller13@xxxxxx wrote:
> > > Hello everybody
> > >
> > > For a science project I am working on a mechanism that hands over
> > > data from a smartphone to a web-browser (=Internet PC). Both connect
> > > to a PHP server. The PHP server has to receive the data (=some kind
> > > of an URL) on the smartphone end and deliver it to the browser end.
> > >
> > > Up to now there have been two (working) implementations. One using
> > > the filesystem the other one using a MySQL Database. The data coming
> > > up from the smartphone is stored in a file/table and some seconds
> > > later sent down to the browser.
> > >
> > >
> > > My question: is it possible to implement this mechanisms just with
> > > PHP methods? I can't think of such a method but need to be sure.
> > >
> > >
> > > Tank you in advance.
> > >
> > > Have a good evening,
> > > Tobias
> > > ___________________________________________________________
> > > Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
> > > Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > What I would do is have the smartphone send some unique identifier
> > along with its data.  For the browser I would have the page refresh at
> > certain time interval, calling a PHP script to see if any data is
> > available for the smartphone's ID.  If you did want the page to keep
> > reloading, you could use AJAX.
> >
> > Take care,
> > Floyd
> 
> 
> 
> Thanks and hello again
> 
> In the current implementation the browser connects to the server using Ajax 
> (XmlHttpRequest=XHR). Personally I prefer sockets too, but sockets don't work 
> with XHR. This will be an option when Websockets or something of that kind 
> becomes widely available. But this part is not what I wish to talk about 
> today (sorry). 
> 
> Today I want to find out how to design the internal data handling. Within the 
> PHP server. Please just think there is already some mechanism that does the 
> data transfer between smartphone, server and browser. The browser polls the 
> server (by XHR) to ask for data. The smartphone will do an (asynchronous GET) 
> request to deliver a data packet to the server. 
> 
> On server side there is one PHP instance that receives the data of the 
> smartphone. And there is another instance that may send the data down to the 
> browser as soon as the data becomes available. It has session variables, a 
> database connection and all of that typical stuff. 
> 
> The (working) method looks like this: the received data packet gets written 
> into the database (by the smartphone PHP instance). And some seconds later 
> the data is read again (by the browser PHP instance). 
> 
> My question is: can this be done without a database? Can one PHP instance 
> (thread, process, ...) hand over data to another PHP instance? 
> 
> 
> (Actually there is an Apache Server that executes PHP scripts. Typical LAMP 
> configuration.)
> 
> 
> Greetings
> Tobias
> 
> 
> 


The short answer is not really. You see, with PHP, the script stops
executing once it's finished sending a response back the the user agent,
be this a browser, smart phone, or other. Also, one instance of PHP is
pretty much unaware of any other instance, which is partly for security,
partly for flexibility and partly just because that's the way it is :p

Having said that, you could run a PHP script as a daemon perhaps, and
listen for the browser and the smart phone with the same script. The
beauty of a daemon is that it's always running, rather than a PHP script
which runs under Apache. However, to run as a Daemon, I believe you will
have to use sockets for transferring data. Doing it this way would allow
you to hold information in memory without having to write it out to the
DB or a file though.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux