Connecting Tech Pros Worldwide Forums | Help | Site Map

background HTTP request

C. (http://symcbean.blogspot.com/)
Guest
 
Posts: n/a
#1: Jan 13 '08
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

<?php

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.

seaside
Guest
 
Posts: n/a
#2: Jan 13 '08

re: background HTTP request


On 13 Jan., 16:05, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
Quote:
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


Closed Thread