Re: [PHP] Help! Having trouble getting one XML field from this feed reliably

2012-02-09 Thread Yared Hufkens
I wonder why you use cURL as SimpleXML itself can load URLs:

$vastdata = new
SimpleXMLElement('http://afe.specificclick.net/?l=32259t=xrnd=123456',0,true);

See http://de.php.net/manual/en/simplexmlelement.construct.php


Am 09.02.2012 04:44, schrieb Rob Gould:
 Can anyone tell me what I'm doing wrong here?  I'm trying to get the 
 VASTAdTagURI field from the XML data at this url:

 http://afe.specificclick.net/?l=32259t=xrnd=123456




 Here's my code.  (below).  It works maybe 30% of the time, but most of the 
 time it just returns nothing from that field.  Yet when I go to the above url 
 in Firefox, I always see the data.  This is very strange.





 // Lets get the ad!

 $curl_handle=curl_init();
 curl_setopt($curl_handle,CURLOPT_URL,'http://afe.specificclick.net/?l=32259t=xrnd=123456');
 curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
 curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
 $buffer = curl_exec($curl_handle);
 curl_close($curl_handle);

 $vastdata = new SimpleXMLElement($buffer);

 $vasturi = $vastdata-Ad-Wrapper-VASTAdTagURI;

 echo If the script works, vasturi =  . $vasturi;

 echo brbrbr;

 print_r($vastdata);








-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help! Having trouble getting one XML field from this feed reliably

2012-02-09 Thread Adam Richardson
On Thu, Feb 9, 2012 at 9:10 AM, Yared Hufkens y4...@yahoo.de wrote:

 I wonder why you use cURL as SimpleXML itself can load URLs:

 $vastdata = new
 SimpleXMLElement('http://afe.specificclick.net/?l=32259t=xrnd=123456
 ',0,true);

 See http://de.php.net/manual/en/simplexmlelement.construct.php


It is pretty convenient that SimpleXMLElement allows you to grab URL's, but
curl allows me to manually set a timeout limit (along with many other
things, although they're not necessarily needed in Rob's example), so I
tend to use curl in this type situation, too.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


[PHP] Help! Having trouble getting one XML field from this feed reliably

2012-02-08 Thread Rob Gould
Can anyone tell me what I'm doing wrong here?  I'm trying to get the 
VASTAdTagURI field from the XML data at this url:

http://afe.specificclick.net/?l=32259t=xrnd=123456




Here's my code.  (below).  It works maybe 30% of the time, but most of the time 
it just returns nothing from that field.  Yet when I go to the above url in 
Firefox, I always see the data.  This is very strange.





// Lets get the ad!

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://afe.specificclick.net/?l=32259t=xrnd=123456');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

$vastdata = new SimpleXMLElement($buffer);

$vasturi = $vastdata-Ad-Wrapper-VASTAdTagURI;

echo If the script works, vasturi =  . $vasturi;

echo brbrbr;

print_r($vastdata);







-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help! Having trouble getting one XML field from this feed reliably

2012-02-08 Thread Adam Richardson
On Wed, Feb 8, 2012 at 10:44 PM, Rob Gould gould...@mac.com wrote:

 Can anyone tell me what I'm doing wrong here?  I'm trying to get the
 VASTAdTagURI field from the XML data at this url:

 http://afe.specificclick.net/?l=32259t=xrnd=123456




 Here's my code.  (below).  It works maybe 30% of the time, but most of the
 time it just returns nothing from that field.  Yet when I go to the above
 url in Firefox, I always see the data.  This is very strange.





 // Lets get the ad!

 $curl_handle=curl_init();
 curl_setopt($curl_handle,CURLOPT_URL,'
 http://afe.specificclick.net/?l=32259t=xrnd=123456');
 curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
 curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
 $buffer = curl_exec($curl_handle);
 curl_close($curl_handle);

 $vastdata = new SimpleXMLElement($buffer);

 $vasturi = $vastdata-Ad-Wrapper-VASTAdTagURI;

 echo If the script works, vasturi =  . $vasturi;

 echo brbrbr;

 print_r($vastdata);


I'd try adding some error checks to see what issues curl may be having:

$str = curl_exec($ch);
$error_no = curl_errno($ch);
curl_close ($ch);

if ($error_no != 0)
throw new Exception('There was an error retrieving the string contents
of the url \''.$url.'\'. CURL error number:'.$error_no);

I wonder if you transaction is timing out, which you can set as below:

curl_setopt($ch, CURLOPT_TIMEOUT, $transaction_timeout = 2);

Adam


-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com