background HTTP request
am 13.01.2008 16:05:13 von colin.mckinnon
Hi all,
I'm dabbling with an Ajax datagrid control and am looking to see if I
can make it a bit more sophisticated.
I've got a PHP script, let's call it page.php which renders a page
with a fancy dhtml table (http://dhtmlx.com/docs/products/dhtmlxGrid/
index.shtml) this connects to another script which provides the XML
datafeed to populate the table, lets call it xmlfeed.php
Despite what it says in the docs, I can't convince the grid to load
its configuration from XML (from xmlfeed.php). The alternate approach
is to configure the table using Javascript which I can generate and
output from within page.php.
So far so good.
But rather than have all the meta-data about the table (column names,
data-types etc) in page.php, I would rather push this down to
xmlfeed.php so I can use the same page.php for different data feeds.
Not a problem....I just setup xmlfeed.php to respond with the meta-
data when started with a particular parameter - eg
if ($_GET['returnMetaData']=='Y') {
// page.php is asking how the table should be configured...
$out=array($output_column_formats, $something else);
return(serialize($out));
} else {
// fetch the data and construct AJAX response...
mysql_connect(...
}
?>
So far, so good. Certainly it would be neater to just include
xmlfeed.php within page.php rather than going out through HTTP, but
that definitely would not allow for the next step....
Because of the way page.php is structured, I can request the metadata
a long time (in the life of page.php) before I need to use the data.
which begs the question, can I have the request running in the
background?
I see the PHP curl library has an option CURLOPT_WRITEFUNCTION to
specify a callback when data is available from the request - does
setting this automatically make the request asynchronous or do I need
to do something else?
(note that starting a shell and invoking a seperate process to fetch
the page and write to a file is expected to be too much of an
overhead).
TIA
C.
Re: background HTTP request
am 13.01.2008 19:06:33 von seaside
On 13 Jan., 16:05, "C. (http://symcbean.blogspot.com/)"
wrote:
> I've got a PHP script, let's call it page.php which renders a page
> with a fancy dhtml table (http://dhtmlx.com/docs/products/dhtmlxGrid/
> index.shtml) this connects to another script which provides the XML
> datafeed to populate the table, lets call it xmlfeed.php
What exactly are you trying to do?
In case you'd like to perform an asynchronous XMLHTTPRequest, I'd
propose
xAjax, since this makes requesting data very simple: Register a PHP
function
with xAjax and call it from within your JS, as if it would be a JS
function:
See here: http://xajaxproject.org/
I wonder, if an asynchronous HTTP request makes any sense in PHP.
Since PHP does not
provide some kind of an event model. Using asychronous CURL calls,
which trigger
a callback, might be risky, since these calls might corrupt PHPs stack
frames etc.
In case URL wrappers are enabled, you might simply wish to use
file_get_contents()
and pass an URL to get the contents of the URL sychnronously.
See here: http://de3.php.net/file_get_contents
Re: background HTTP request
am 14.01.2008 14:47:11 von colin.mckinnon
On 13 Jan, 18:06, seaside wrote:
> On 13 Jan., 16:05, "C. (http://symcbean.blogspot.com/)"
>
> wrote:
> > I've got a PHP script, let's call it page.php which renders a page
> > with a fancy dhtml table (http://dhtmlx.com/docs/products/dhtmlxGrid/
> > index.shtml) this connects to another script which provides the XML
> > datafeed to populate the table, lets call it xmlfeed.php
>
> What exactly are you trying to do?
>
> In case you'd like to perform an asynchronous XMLHTTPRequest, I'd
> propose
> xAjax, since this makes requesting data very simple: Register a PHP
> function
> with xAjax and call it from within your JS, as if it would be a JS
> function:
> See here:http://xajaxproject.org/
Fine, if the metadata request was originating at the browser - but I'm
trying to create a request from PHP (to generate the page which will
then make an AJAX request). My PHP script needs to know the metadata
in order to set up the page - its just a matter of convenience to use
the same script for metadata and data.
>
> I wonder, if an asynchronous HTTP request makes any sense in PHP.
> Since PHP does not
> provide some kind of an event model. Using asychronous CURL calls,
> which trigger
> a callback, might be risky, since these calls might corrupt PHPs stack
> frames etc.
? debug_backtrace() and register_tick_function() seem to operate
without corrupting the stack frame.
>
> In case URL wrappers are enabled, you might simply wish to use
> file_get_contents()
> and pass an URL to get the contents of the URL sychnronously.
> See here:http://de3.php.net/file_get_contents
....but the point of my post is that I want to do it asynchronously.
C.