<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHPBSD.net &#187; curl</title>
	<atom:link href="http://www.phpbsd.net/tag/curl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpbsd.net</link>
	<description>Blogueando sobre PHP, BSD, SEO, AJAX, Seguridad, Rendimiento... y mucho más</description>
	<lastBuildDate>Mon, 30 Nov 2009 11:28:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Transfiriendo datos con la librería cURL en PHP</title>
		<link>http://www.phpbsd.net/2007/01/31/transfiriendo-datos-con-la-libreria-curl-en-php/</link>
		<comments>http://www.phpbsd.net/2007/01/31/transfiriendo-datos-con-la-libreria-curl-en-php/#comments</comments>
		<pubDate>Wed, 31 Jan 2007 01:39:25 +0000</pubDate>
		<dc:creator>Oriol</dc:creator>
				<category><![CDATA[Artículos]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[libcurl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[webmaster]]></category>

		<guid isPermaLink="false">http://www.phpbsd.net/2007/01/31/transfiriendo-datos-con-la-libreria-curl-en-php/</guid>
		<description><![CDATA[cURL es una utilidad de linea de comandos (curl) y una librería (libcurl) para realizar transferencias de archivos que soporta multitud de protocolos distintos (FTP, HTTP, etc.) y un sinfín de opciones. Tanto la utilidad como la librería son muy conocidas y de un uso muy extendido.
La librería se puede usar desde varios lenguajes de [...]


Entradas relacionadas:<ul><li><a href='http://www.phpbsd.net/2007/02/06/datos-xml-bonitos-y-mas-leibles-en-php-usando-pear-xml_beautifier/' rel='bookmark' title='Permanent Link: Datos XML bonitos y más leíbles en PHP usando PEAR XML_Beautifier'>Datos XML bonitos y más leíbles en PHP usando PEAR XML_Beautifier</a></li><li><a href='http://www.phpbsd.net/2007/02/09/leyendo-xml-desde-php-con-simplexml/' rel='bookmark' title='Permanent Link: Leyendo XML desde PHP con SimpleXML'>Leyendo XML desde PHP con SimpleXML</a></li><li><a href='http://www.phpbsd.net/2007/01/14/capturando-los-fatal-errors-del-php-con-nuestro-handler/' rel='bookmark' title='Permanent Link: Capturando los fatal errors del PHP con nuestro handler'>Capturando los fatal errors del PHP con nuestro handler</a></li></ul>]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://curl.haxx.se/" title="cURL and libcurl">cURL</a> es una utilidad de linea de comandos (curl) y una librería (libcurl) para realizar transferencias de archivos que soporta multitud de protocolos distintos (FTP, HTTP, etc.) y un sinfín de opciones. Tanto la utilidad como la librería son muy conocidas y de un uso muy extendido.</p>
<p>La librería se puede usar desde varios lenguajes de programación y entre ellos, como no, el PHP. Puedes encontrar en el manual todo un capítulo dedicado al <a target="_blank" href="http://es2.php.net/manual/en/ref.curl.php" title="PHP: CURL, Client URL Library Functions - Manual">conjunto de funciones cURL</a>. De entre la infinidad de cosas que puedes hacer usando esta librería con PHP: obtener el contenido de una web, obtener datos XML (como RSS), subir o bajar archivos de servidores FTP, soporte para conexiones seguras (HTTPS, SCP), etc. Una opción destacable es el soporte de peticiones HTTP POST y GET con lo que podéis realizar <a target="_blank" href="http://en.wikipedia.org/wiki/Web_scraping" title="Web scraping - Wikipedia, the free encyclopedia">scraping</a> de casi cualquier cosa.</p>
<p>Un ejemplo de código para obtener el contenido de una página web (o un feed):</p>
<div class="syntax_hilite">
<div id="php-2">
<div class="php"><span style="color:#0000FF;">$ch</span> = curl_init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_URL, <span style="color:#FF0000;">'http://www.phpbsd.net/'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_HEADER, <span style="color:#000000; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
curl_setopt <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_RETURNTRANSFER, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#0000FF;">$resultado</span> = curl_exec<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#0000FF;">$error</span> = curl_error<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
curl_close<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p>Con el código anterior en <em>$resultado</em> nos quedamos con los datos obtenidos o nada si ha ocurrido un error, si ese es el caso en <em>$error</em> tenemos un mensaje de texto con el error. Se usan las siguientes opciones:</p>
<ul>
<li><strong>CURLOPT_URL</strong> con la URL a descargar.</li>
<li><strong>CURLOPT_HEADER</strong> a false para no incluir las headers HTTP en la respuesta.</li>
<li><strong>CURLOPT_RETURNTRANSFER</strong> a true para que la función <em>curl_exec()</em> devuelva la respuesta como un string en lugar de printarla por pantalla.</li>
</ul>
<p>Para más opciones consultar la documentación de la función <em>curl_setopt()</em>.</p>
<p>De todas las funcionalidades que proporciona el soporte de cURL en PHP una de las más llamativas son todas las funciones <em>multi_*</em> para realizar peticiones en paralelo, esto puede llegar a ser muy útil en numerosas situaciones. En un siguiente post explicaré como lanzar peticiones paralelas desde PHP usando cURL.</p>


<p>Entradas relacionadas:<ul><li><a href='http://www.phpbsd.net/2007/02/06/datos-xml-bonitos-y-mas-leibles-en-php-usando-pear-xml_beautifier/' rel='bookmark' title='Permanent Link: Datos XML bonitos y más leíbles en PHP usando PEAR XML_Beautifier'>Datos XML bonitos y más leíbles en PHP usando PEAR XML_Beautifier</a></li><li><a href='http://www.phpbsd.net/2007/02/09/leyendo-xml-desde-php-con-simplexml/' rel='bookmark' title='Permanent Link: Leyendo XML desde PHP con SimpleXML'>Leyendo XML desde PHP con SimpleXML</a></li><li><a href='http://www.phpbsd.net/2007/01/14/capturando-los-fatal-errors-del-php-con-nuestro-handler/' rel='bookmark' title='Permanent Link: Capturando los fatal errors del PHP con nuestro handler'>Capturando los fatal errors del PHP con nuestro handler</a></li></ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.phpbsd.net/2007/01/31/transfiriendo-datos-con-la-libreria-curl-en-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
