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

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

 



On Wed, Feb 8, 2012 at 10:44 PM, Rob Gould <gouldimg@xxxxxxx> 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=32259&t=x&rnd=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=32259&t=x&rnd=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 "<br><br><br>";
>
> 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

[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