<?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>Php Development &#187; curl</title>
	<atom:link href="http://www.maheshchari.com/tag/curl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maheshchari.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 17 Jan 2012 02:42:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>simple curl function to send data remote server</title>
		<link>http://www.maheshchari.com/simple-curl-function-to-send-data-remote-server/</link>
		<comments>http://www.maheshchari.com/simple-curl-function-to-send-data-remote-server/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 04:49:43 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[curl]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=560</guid>
		<description><![CDATA[simple PHP curl function below example function is used to send the form data or post data to remote server . i have mentioned detailed explanation on comments. Code Download Code function curl&#40;$url, $method = 'get', $header = null, $postdata = null, $timeout = 60&#41; &#123; $s = curl_init&#40;&#41;; // initialize curl handler &#160; curl_setopt&#40;$s,CURLOPT_URL, [...]]]></description>
			<content:encoded><![CDATA[<h1>simple PHP curl function </h1>
<p>below example function is used to send the form data or post data to remote server . i have mentioned detailed explanation on comments. </p>
<h2>Code</h2>
<h2><a href='http://www.maheshchari.com/wp-content/uploads/2010/11/curl.zip'>Download Code</a></h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> curl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'get'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postdata</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// initialize curl handler </span>
&nbsp;
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//set option  URL of the location </span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span> 
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_HTTPHEADER<span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//set headers if presents</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//time out of the curl handler  		</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//time out of the curl socket connection closing </span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_MAXREDIRS<span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//set maximum URL redirections to 3 </span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// set option curl to return as string ,don't output directly</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_COOKIEJAR<span style="color: #339933;">,</span> <span style="color: #0000ff;">'cookie.txt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_COOKIEFILE<span style="color: #339933;">,</span> <span style="color: #0000ff;">'cookie.txt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #666666; font-style: italic;">//set a cookie text file, make sure it is writable chmod 777 permission to cookie.txt</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//set curl option to post method</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$postdata</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//if post data present send them.</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'delete'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_CUSTOMREQUEST<span style="color: #339933;">,</span> <span style="color: #0000ff;">'DELETE'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//file transfer time delete</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'put'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_CUSTOMREQUEST<span style="color: #339933;">,</span> <span style="color: #0000ff;">'PUT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$postdata</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//file transfer to post ,put method and set data</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			 
		<span style="color: #666666; font-style: italic;">// curl send header </span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span>CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #0000ff;">'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//proxy as Mozilla browser </span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// don't need to SSL verify ,if present it need openSSL PHP extension</span>
&nbsp;
		<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//run handler</span>
&nbsp;
		<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_getinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span> CURLINFO_HTTP_CODE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// get the response status</span>
&nbsp;
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//close handler</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//return output</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2><a href='http://www.maheshchari.com/wp-content/uploads/2010/11/curl.zip'>Download Code</a></h2>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=560&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/simple-curl-function-to-send-data-remote-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Upload Image File To Remote Server With PHP cURL</title>
		<link>http://www.maheshchari.com/upload-image-file-to-remote-server-with-php-curl/</link>
		<comments>http://www.maheshchari.com/upload-image-file-to-remote-server-with-php-curl/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 23:40:55 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=538</guid>
		<description><![CDATA[How to upload image file to remote server with PHP cURL In this example we learn how to upload static files to remote server using PHP cURL library. We must know following functionality before we continue this example PHP file upload functionality. cURL function reference. how to submit data to remote server with PHP cURL [...]]]></description>
			<content:encoded><![CDATA[<h1>How to upload image file to remote server with PHP cURL</h1>
<p>In this example we learn how to upload static files to remote server using PHP cURL library.</p>
<h3>We must know following functionality before we continue this example</h3>
<ul>
<li><a href="http://www.maheshchari.com/simple-php-file-upload-tutorial/" target="_blank">PHP file upload functionality.</a></li>
<li><a href="http://www.maheshchari.com/php-curl-basic-reference/">cURL function reference.</a></li>
<li><a href="http://www.maheshchari.com/submitting-form-to-remote-server-with-array-of-parameters/" target="_blank">how to submit data to remote server with PHP cURL</a></li>
</ul>
<h3>Files and Folders</h3>
<h3><a href='http://www.maheshchari.com/wp-content/uploads/2010/03/curl_image.zip'>Download Example</a></h3>
<p>For this example we use three files </p>
<ul>
<li><strong>uploader.php</strong> -that receives the files on to the remote server.</li>
<li><strong>handler.php</strong> -is used to web based client to upload the file.</li>
<li><strong>curl_handler.php</strong> -PHP cURL uploading client to upload file.</li>
</ul>
<p>Since we use same host to both local and remote server ,we create separate directories</p>
<ul>
<li><strong>local_files/ </strong>- these files will be uploaded to the remote server ,means to <strong>uploaded_files</strong> directory.</li>
<li><strong>uploaded_files/</strong> &#8211; these files are from the uploading client from both <strong>web based </strong>and <strong>PHP cURL based</strong>.</li>
</ul>
<h3>uploader.php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$upload_directory</span><span style="color: #339933;">=</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/uploaded_files/'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//check if form submitted</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'upload'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #666666; font-style: italic;">//check for image submitted</span>
    		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #666666; font-style: italic;">// check for error re file</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Error: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;my_file&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//move temp file to our server            </span>
			<span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> 
			<span style="color: #000088;">$upload_directory</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Uploaded File.'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'File not uploaded.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			<span style="color: #666666; font-style: italic;">// exit script</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>handler.php</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;uploader.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; name=&quot;form1&quot; id=&quot;form1&quot;&gt;
  &lt;input type=&quot;file&quot; name=&quot;my_file&quot; id=&quot;my_file&quot; /&gt;
  &lt;input type=&quot;submit&quot; name=&quot;upload&quot; id=&quot;upload&quot; value=&quot;Upload&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<h3>curl_handler.php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$local_directory</span><span style="color: #339933;">=</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/local_files/'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_VERBOSE<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Mozilla/4.0 (compatible;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://localhost/curl_image/uploader.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//most importent curl assues @filed as file field</span>
    <span style="color: #000088;">$post_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">&quot;my_file&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;@&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$local_directory</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'shreya.jpg'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">&quot;upload&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Upload&quot;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$post_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span></pre></div></div>

<h3><a href='http://www.maheshchari.com/wp-content/uploads/2010/03/curl_image.zip'>Download Example</a></h3>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=538&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/upload-image-file-to-remote-server-with-php-curl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Submitting form to remote server with array of parameters</title>
		<link>http://www.maheshchari.com/submitting-form-to-remote-server-with-array-of-parameters/</link>
		<comments>http://www.maheshchari.com/submitting-form-to-remote-server-with-array-of-parameters/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 01:04:34 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[curl]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=454</guid>
		<description><![CDATA[submit a form with post method to remote server using php curl We learn how to submit the form data to remote server in my previous example with URL string. Here we can pass data with POST multipart method,main difference is that we passs it as array. To submit forms using cURL, we need to [...]]]></description>
			<content:encoded><![CDATA[<h1>submit a form with post method to remote server using php curl</h1>
<p>We learn how to submit the form data to remote server in my <a href="http://www.maheshchari.com/submit-a-form-to-remote-server-with-php-curl/">previous example</a> with URL string.<br />
Here we can pass data with POST multipart method,main difference is that we passs it as array.</p>
<p>To submit forms using cURL, we need to follow the below steps:</p>
<p> 1. Prepare the data to be posted<br />
  2. Connect to the remote URL<br />
  3. Post (submit) the data<br />
  4. Fetch response and display it to the user or do some other stuff with it.</p>
<p>Below Example Has two files,one to post the data and other is to process the data.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
 * Data which is to submitted to the remote URL
 */</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$post_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fname'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'mahesh'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'lname'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'chari'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Initialize cURL and connect to the remote URL
 * You will need to replace the URL with your own server's URL
 * or wherever you uploaded this script to. 
 */</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://example.com/curlpost_handler.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Instruct cURL to do a regular HTTP POST
 */</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Specify the data which is to be posted
 */</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$post_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Tell curl_exec to return the response output as a string
 */</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Execute the cURL session
 */</span>
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Close cURL session and file
 */</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// is Welcome Maheshchari.</span></pre></div></div>

<p>Handling post data on curlpost_hanlder.php </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$firstname</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$lastname</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>Welcome <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;.</span><span style="color: #000088;">$firstname</span><span style="color: #339933;">.</span><span style="color: #000088;">$lastname</span><span style="color: #339933;">;</span></pre></div></div>

<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=454&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/submitting-form-to-remote-server-with-array-of-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>submit a form to remote server with php curl</title>
		<link>http://www.maheshchari.com/submit-a-form-to-remote-server-with-php-curl/</link>
		<comments>http://www.maheshchari.com/submit-a-form-to-remote-server-with-php-curl/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 01:00:03 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[remote server]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=451</guid>
		<description><![CDATA[Submitting form to remote server. We learned some basics in my previous article cURL basics. Here we cover a topic how to submit a form to remote server. To submit forms using cURL, we need to follow the below steps: 1. Prepare the data to be posted 2. Connect to the remote URL 3. Post [...]]]></description>
			<content:encoded><![CDATA[<h1>Submitting form to remote server.</h1>
<p>We learned some basics in my <a href="http://www.maheshchari.com/php-curl-basic-reference/" target="_blank">previous article</a> cURL basics. Here we cover a topic how to submit a form to remote server.</p>
<p>To submit forms using cURL, we need to follow the below steps:</p>
<p> 1. Prepare the data to be posted<br />
  2. Connect to the remote URL<br />
  3. Post (submit) the data<br />
4. Fetch response and display it to the user or do some other stuff with it.</p>
<p>Below Example Has two files,one to post the data and other is to process the data.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
 * Data which is to submitted to the remote URL
 */</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$post_str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fname=mahesh&amp;lname=chari&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Initialize cURL and connect to the remote URL
 * You will need to replace the URL with your own server's URL
 * or wherever you uploaded this script to. 
 */</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://example.com/curlpost_handler.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Instruct cURL to do a regular HTTP POST
 */</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Specify the data which is to be posted
 */</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$post_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Tell curl_exec to return the response output as a string
 */</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Execute the cURL session
 */</span>
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Close cURL session and file
 */</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// is Welcome Maheshchari.</span></pre></div></div>

<p>Handling post data on curlpost_hanlder.php </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$firstname</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$lastname</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Welcome &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$firstname</span><span style="color: #339933;">.</span><span style="color: #000088;">$lastname</span><span style="color: #339933;">;</span></pre></div></div>

<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=451&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/submit-a-form-to-remote-server-with-php-curl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>php curl basic reference</title>
		<link>http://www.maheshchari.com/php-curl-basic-reference/</link>
		<comments>http://www.maheshchari.com/php-curl-basic-reference/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 00:54:50 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[curl]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=448</guid>
		<description><![CDATA[cURL basics and functions over view cURL is a PHP library which allows you to connect and communicate to many different types of servers with many different types of protocols.Main difference is it has session capability unlik fopen. We can make small scale robot script with cURL functions in PHP. With cURL we can: Implement [...]]]></description>
			<content:encoded><![CDATA[<h1>cURL basics and functions over view</h1>
<p>cURL is a PHP library which allows you to  connect and communicate to many different types of servers with many  different types of protocols.Main difference is it has session capability unlik <a href="http://php.net/manual/en/function.fopen.php" target="_blank">fopen</a>. We can make small scale robot script with cURL functions in PHP.</p>
<p>With  cURL we can:</p>
<ul>
<li>Implement payment gateways’ payment notification scripts.</li>
<li>Download and upload files from remote servers.</li>
<li>Login to other websites and access members only sections.</li>
<li>Cross site communication with PHP backend and Ajax.</li>
</ul>
<p>PHP cURL library is definitely the odd man out. Unlike other PHP libraries where a whole plethora of functions is made available, PHP cURL wraps up a major parts of its functionality with following functions.</p>
<p>Curl functions are:</p>
<ol>
<li>  <strong>curl_close</strong> — Close a cURL session</li>
<li>    <strong>curl_copy_handle </strong>— Copy a cURL handle along with all of its preferences</li>
<li>    <strong>curl_errno</strong> — Return the last error number</li>
<li>    <strong>curl_error</strong> — Return a string containing the last error for the current session</li>
<li>    <strong>curl_exec</strong> — Perform a cURL session</li>
<li><strong>curl_getinfo</strong> — Get information regarding a specific transfer</li>
<li>    <strong>curl_init</strong> — Initialize a cURL session</li>
<li>    <strong>curl_multi_add_handle</strong> — Add a normal cURL handle to a cURL multi handle</li>
<li>    <strong>curl_multi_close</strong> — Close a set of cURL handles</li>
<li>    <strong>curl_multi_exec</strong> — Run the sub-connections of the current cURL handle</li>
<li>    <strong>curl_multi_getcontent</strong> — Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set</li>
<li>    <strong>curl_multi_info_read</strong> — Get information about the current transfers</li>
<li>    <strong>curl_multi_init</strong> — Returns a new cURL multi handle</li>
<li><strong> curl_multi_remove_handle</strong> — Remove a multi handle from a set of cURL handles</li>
<li>    <strong>curl_multi_select</strong> — Wait for activity on any curl_multi connection</li>
<li>    <strong>curl_setopt_array</strong> — Set multiple options for a cURL transfer</li>
<li>    <strong>curl_setopt</strong> — Set an option for a cURL transfer</li>
<li>    <strong>curl_version </strong>— Gets cURL version information</li>
</ol>
<p><strong>curl_setopt </strong>is the pivot around which the main cURL functionality revolves. cURL functioning is controlled by way of passing predefined <a href="http://www.php.net/manual/en/function.curl-setopt.php" target="_blank">options</a> and values to this function.</p>
<h3>A simple example to handle google rss feed<br />
</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">/*
*
* Initialize the cURL session
*/</span>
<span style="color: #000088;">$curl_handler</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
*
* Set the URL of the page or file to download.
*/</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handler</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span>
<span style="color: #0000ff;">'http://news.google.com/news?hl=en&amp;topic=t&amp;output=rss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
*
* Ask cURL to return the contents in a variable
* instead of simply echoing them to the browser.
*/</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handler</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
*
* Execute the cURL session,do some stuff with content
*/</span>
<span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
*
* Close cURL session,
*be sure to close the handler as curl stores cookies ,other file data stores on server.
*/</span>
<span style="color: #990000;">curl_close</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl_handler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the above example we used CURLOPT_URL,CURLOPT_RETURNTRANSFER options.</p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=448&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/php-curl-basic-reference/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>php cron job</title>
		<link>http://www.maheshchari.com/php-cron-job/</link>
		<comments>http://www.maheshchari.com/php-cron-job/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 17:01:40 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[curl]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=407</guid>
		<description><![CDATA[Setup Cron Job with PHP without crontab that runs every minute. Cron job is scheduling some tasks with in regular interval on server.To setup cron job we must know about the cron tab commonds and shell access to remote server. generelly every hosting providers provide some programs like cPanel. Here we run a cron job [...]]]></description>
			<content:encoded><![CDATA[<h1>Setup Cron Job with PHP without crontab that runs every minute.</h1>
<p><strong>Cron job</strong> is scheduling some tasks with in regular interval on server.To setup cron job we must know about the cron tab commonds and shell access to remote server. generelly every hosting providers provide some programs like cPanel. Here we run a <strong>cron job</strong> that runs every mintues automatically without <strong>cron tab unix / linux demon </strong>or without any <strong>externel</strong> progams.</p>
<p>Generelly <strong>Cron job</strong> will run atleast four hours gap on <strong>cPanel</strong> or <strong>Plesk</strong> ,so it is not possible to setup cron job every minute unless you have crontab demon on server , <strong>SSH </strong>account on server. Here we write a simple php script that calls itself at every minute. </p>
<p>Remmber this cron job runs with <strong>curl php</strong> extension.</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//This function runs with curl extension that calls or open remote file.</span>
<span style="color: #000000; font-weight: bold;">function</span> call_remote_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> do_somework<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//This function to run every minutes</span>
<span style="color: #339933;">@</span><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mahesh@gmail.com'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'cron job'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'cron runned'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// some web hosts will have only 30 sec max execution time so we keep it unlimited time</span>
<span style="color: #666666; font-style: italic;">// this function only runs if safe mode is off</span>
<span style="color: #000088;">$url</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.maheshchari.com/cronjob.php&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//it is the script that runs exactly every minutes</span>
call_remote_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
do_somework<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//in mean time run some work</span>
<span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// wait the script for 60 seconds or every minute</span>
call_remote_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// call this script itself after a minute</span>
<span style="color: #666666; font-style: italic;">// This process continues every minute</span></pre></td></tr></table></div>

<p>To stop this cron job simple remove the file from server. </p>
<p>With this script we don&#8217;t need</p>
<ul>
<li>SSH /SFTP account</li>
<li>No need of learning cron tab commonds.</li>
<li>No script php exec permissions.</li>
<li>No need to turn off php safe mode.</li>
</ul>
<h3><a href='http://www.maheshchari.com/wp-content/uploads/2010/02/cron.zip'>Download Demo</a></h3>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=407&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/php-cron-job/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

