W3C home > Mailing lists > Public > public-lod@w3.org > January 2010

Re: PHP RDF fetching code

From: Mischa Tuffield <mmt04r@ecs.soton.ac.uk>
Date: Mon, 25 Jan 2010 20:01:59 +0000
Cc: "public-lod@w3.org" <public-lod@w3.org>
Message-ID: <EMEW3|3089babd4fd958569910ccde94c77506m0OK2106mmt04r|ecs.soton.ac.uk|70137829-28B8-4E4D-AE65-9A1D21F02125@ecs.soton.ac.uk>
To: Hugh Glaser <hg@ecs.soton.ac.uk>
Hi Hugh, 

The code you posted seems sane to me. It is very similar to the php we use to make sparql-queries. My only comment being that you probably want to have a line which closes curl connection after you have used it.

something like : 

<!--
curl_close($ch);
-->

You could also set a User Agent, to identify your self to the website's you are fetching RDF from, you would do it like so : 

<!--
curl_setopt($ch, CURLOPT_USERAGENT, "hugh's crawler 0.1");
-->

I hope this helps, 

Mischa

On 25 Jan 2010, at 18:10, Hugh Glaser wrote:

> OK, hereís some fun for you...
> (Excuse me if it has been discussed before, and just point me at it :-) )
> 
> 
> Having struggled through the php manual for cURL, I have come up with the following draft for getting an RDF document, given a URI.
> 
>                        $ch = curl_init();
>                        curl_setopt($ch, CURLOPT_URL, $_REQUEST['uri']);
>                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
>                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
>                        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/rdf+xml, text/n3, text/rdf+n3, text/turtle, application/x-turtle, application/turtle, text/plain"));
>                        $data = curl_exec($ch);
>                        $info = curl_getinfo($ch);
> 
>                        if ($data === FALSE || $info['http_code'] != 200) {
> 
> What does anyone think?
> Iím sure there are a bunch of improvements/corrections.
> 
> As a (hopefully) separate issue, the MIME types will probably generate some discussion, but it is the PHP I am primarily asking about at the moment.
> 
> Best
> Hugh
> 

_________________________________
Mischa Tuffield
ECS - http://www.ecs.soton.ac.uk/
Homepage - http://users.ecs.soton.ac.uk/mmt04r/
Identity - http://id.ecs.soton.ac.uk/person/6914
WebID - http://mmt.me.uk/foaf.rdf#mischa
Received on Tuesday, 26 January 2010 13:26:10 UTC

This archive was generated by hypermail 2.3.1 : Sunday, 31 March 2013 14:24:24 UTC