<?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>Incero &#187; php</title>
	<atom:link href="http://www.incero.com/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.incero.com</link>
	<description>Dedicated Server</description>
	<lastBuildDate>Fri, 03 Feb 2012 06:48:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Number Of Available CPU Cores In PHP</title>
		<link>http://www.incero.com/webdev/number-of-available-processing-cores-in-php</link>
		<comments>http://www.incero.com/webdev/number-of-available-processing-cores-in-php#comments</comments>
		<pubDate>Thu, 01 Jul 2010 04:26:22 +0000</pubDate>
		<dc:creator>Gordon</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[cores]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[cpus]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[processor]]></category>

		<guid isPermaLink="false">http://www.incero.com/?p=539</guid>
		<description><![CDATA[It is simple enough to check and then load the number of available processing cores on the current machine into a PHP variable. You can do so with the code below, which uses shell commands to grab data from /proc/cpuinfo and then removes unneeded data with PHP. &#60;?php /*How to check how many processors are [...]]]></description>
			<content:encoded><![CDATA[<p>It is simple enough to check and then load the number of available processing cores on the current machine into a PHP variable. You can do so with the code below, which uses shell commands to grab data from /proc/cpuinfo and then removes unneeded data with PHP.</p>
<pre class="brush: php;">&lt;?php
 /*How to check how many processors are available on the current machine.
 by gordon@incero.com http://www.Incero.com. Feel free to use this code,
 but keep this header. June 30th, 2010.*/
 $numberOfProcessors=`cat /proc/cpuinfo | grep processor | tail -1`;
 $numberOfProcessors=preg_replace('/\s+/', '',$numberOfProcessors);
 $numberOfProcessors=str_replace(&quot;:&quot;,&quot;&quot;, $numberOfProcessors);
 $numberOfProcessors=str_replace(&quot;processor&quot;,&quot;&quot;, $numberOfProcessors);
 $numberOfProcessors++;
 echo &quot;Number of processors on this machine is $numberOfProcessors!&quot;;
?&gt;</pre>
<p>We use this code to help our programs assign the most efficient parameters to others processes, such as FFMpeg video conversions, that we spawn from PHP across various machines.</p>
<p>Tested on CentOS 5.4, should work on most Linux distributions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.incero.com/webdev/number-of-available-processing-cores-in-php/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How To Generate Thumbnails On The Fly With PHP</title>
		<link>http://www.incero.com/webdev/how-to-generate-thumbnails-on-the-fly-with-php</link>
		<comments>http://www.incero.com/webdev/how-to-generate-thumbnails-on-the-fly-with-php#comments</comments>
		<pubDate>Fri, 30 Apr 2010 21:25:03 +0000</pubDate>
		<dc:creator>Gordon</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[exif]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[thumbnail]]></category>

		<guid isPermaLink="false">http://www.incero.com/?p=420</guid>
		<description><![CDATA[There are two great ways to generate thumbnails for images on the fly with PHP: Use GD to resize the image on the fly and output it Extracts the thumbnail from the Exif data. (If this fails, you could revert to method 1 above.) The latter assumes that the image file has exif data, which [...]]]></description>
			<content:encoded><![CDATA[<p>There are two great ways to generate thumbnails for images on the fly with PHP:</p>
<ol>
<li> Use GD to resize the image on the fly and output it</li>
<li>Extracts the thumbnail from the <a href="http://en.wikipedia.org/wiki/Exchangeable_image_file_format" target="_blank">Exif data</a>. (If this fails, you could revert to method 1 above.)</li>
</ol>
<p>The latter assumes that the image file has exif data, which most photos  do. To ensure the fastest loading thumbnails it would be best to generate thumbnails when images are uploaded to the server, but there are times when you don&#8217;t want to have to store thumbnails for every image uploaded.</p>
<p><strong>Method 1: Using GD To Resize On The Fly</strong></p>
<p>Using this <a href="http://www.incero.com/codesamples/thumbnailonthefly/highres.jpg" target="_blank">8.5MB image</a>, and the code below, the following URL will load a thumbnail that is dynamically created: <a href="http://www.incero.com/codesamples/thumbnailonthefly/thumbnail.php?image=highres.jpg&amp;width=160" target="_blank">http://www.incero.com/codesamples/thumbnailonthefly/thumbnail.php?image=highres.jpg&amp;width=160</a></p>
<pre class="brush: php;">&lt;?php
 /*How to extract a thumbnail from Exif data using PHP
 Created by Gordon Page, gordon@incero.com. April 30th, 2010.
 Incero.com offers custom coding and hosting solutions.
 */
 header(&quot;Content-type: image/jpeg&quot;);

 // get image size
 $file = $_GET[image];
 if($size = GetImageSize($file)){
 $w = $size[0];
 $h = $size[1];
 //set new size
 $nw = $_GET['width'];
 $nh = ($nw*$h)/$w;
 }
 else{
 //set new size
 $nw = &quot;160&quot;;
 $nh = &quot;120&quot;;
 }
 //draw the image
 $src_img = imagecreatefromjpeg($file);
 $dst_img = imagecreatetruecolor($nw,$nh);
 imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image
 imagejpeg($dst_img,&quot;&quot;,100);
 imagedestroy($src_img);
 imagedestroy($dst_img);
?&gt;</pre>
<p>You&#8217;ll notice that with this method it takes about a second to generate the thumbnail so you may want to default to the method below which is faster, and if that method fails then fall back to this first method.</p>
<p><strong>Method 2: Extracting The Thumbnail From The Exif Data<br />
</strong></p>
<p>Using the same <a href="http://www.incero.com/codesamples/thumbnailonthefly/highres.jpg" target="_blank">8.5MB  image</a>, and the code below, the following URL will extract the thumbnail from the Exif data: <a href="http://www.incero.com/codesamples/thumbnailonthefly/exifthumb.php?image=highres.jpg" target="_blank">http://www.incero.com/codesamples/thumbnailonthefly/exifthumb.php?image=highres.jpg</a><a href="http://www.incero.com/codesamples/thumbnailonthefly/thumbnail.php?image=highres.jpg&amp;width=160" target="_blank"></a></p>
<pre class="brush: php;">

&lt;?php
 /*How to extract a thumbnail from Exif data using PHP
 Created by Gordon Page, gordon@incero.com. April 30th, 2010.
 Incero.com offers custom coding and hosting solutions.
 */
 // file to read
 $file =$_REQUEST['image'];
 $image = exif_thumbnail($file, $width, $height, $type);
 // width, height and type get filled with data
 // after calling &quot;exif_thumbnail&quot;
 if ($image) {
 // send header and image data to the browser:
 header('Content-type: ' .image_type_to_mime_type($type));
 print $image;
 }
 else {
 // there is no thumbnail available, handle the error.
 //This would be a great place to revert to the GD resize method.
 print 'No thumbnail available';
 }
?&gt;
</pre>
<p>Feel free to use the code above in your own projects. If you are in need of paid programming services please <a href="/contact-us">contact us</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.incero.com/webdev/how-to-generate-thumbnails-on-the-fly-with-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Uploading To FTP Using PHP and CURL</title>
		<link>http://www.incero.com/webdev/uploading-to-ftp-using-php-and-curl</link>
		<comments>http://www.incero.com/webdev/uploading-to-ftp-using-php-and-curl#comments</comments>
		<pubDate>Thu, 15 Oct 2009 23:11:42 +0000</pubDate>
		<dc:creator>Gordon</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.incero.com/?p=246</guid>
		<description><![CDATA[An interesting project that I was working on today required grabbing remote files to a server and then pushing them to a remote FTP server. PHP has built in FTP functions, but there are many reasons that you might want to use CURL instead. Here is the code that I used to upload to FTP, [...]]]></description>
			<content:encoded><![CDATA[<p>An interesting project that I was working on today required grabbing remote files to a server and then pushing them to a remote FTP server.</p>
<p>PHP has built in FTP functions, but there are many reasons that you might want to use CURL instead.</p>
<p>Here is the code that I used to upload to FTP, slightly modified for portability:</p>
<p>&lt;?php<br />
$ch = curl_init();<br />
$localfile = &#8220;test.tar&#8221;;<br />
$fp = fopen($localfile, &#8216;r&#8217;);</p>
<p>curl_setopt($ch, CURLOPT_URL, &#8216;ftp://username:password@ftp.domain.com/public_html/filesfromscript/&#8217;.$localfile);<br />
curl_setopt($ch, CURLOPT_UPLOAD, 1);<br />
curl_setopt($ch, CURLOPT_INFILE, $fp);<br />
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));</p>
<p>curl_exec ($ch);<br />
$error_no = curl_errno($ch);<br />
curl_close ($ch);</p>
<p>if ($error_no == 0) {<br />
$message = &#8216;File uploaded successfully.&#8217;;<br />
} else {<br />
$message = &#8220;File upload error: $error_no. Error codes explained here http://curl.haxx.se/libcurl/c/libcurl-errors.html&#8221;;<br />
}<br />
echo $message;<br />
?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.incero.com/webdev/uploading-to-ftp-using-php-and-curl/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking Remote File Size With PHP</title>
		<link>http://www.incero.com/webdev/checking-remote-file-size-with-php</link>
		<comments>http://www.incero.com/webdev/checking-remote-file-size-with-php#comments</comments>
		<pubDate>Thu, 15 Oct 2009 18:13:03 +0000</pubDate>
		<dc:creator>Gordon</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[size]]></category>

		<guid isPermaLink="false">http://www.incero.com/?p=239</guid>
		<description><![CDATA[If you&#8217;re going to grab a file from a remote server using PHP it may be useful to know how large the file is before grabbing it. We can check the remote file headers for the file size by using CURL like so: function remote_filesize($url, $user = &#8220;&#8221;, $pw = &#8220;&#8221;) { ob_start(); $ch = [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re going to grab a file from a remote server using PHP it may be useful to know how large the file is before grabbing it. We can check the remote file headers for the file size by using CURL like so:</p>
<blockquote><p>function remote_filesize($url, $user = &#8220;&#8221;, $pw = &#8220;&#8221;) {<br />
ob_start();<br />
$ch = curl_init($url);<br />
curl_setopt($ch, CURLOPT_HEADER, 1);<br />
curl_setopt($ch, CURLOPT_NOBODY, 1);</p>
<p>if(!empty($user) &amp;&amp; !empty($pw))<br />
{<br />
$headers = array(&#8216;Authorization: Basic &#8216; . base64_encode(&#8220;$user:$pw&#8221;));<br />
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);<br />
}</p>
<p>$ok = curl_exec($ch);<br />
curl_close($ch);<br />
$head = ob_get_contents();<br />
ob_end_clean();</p>
<p>$regex = &#8216;/Content-Length:s([0-9].+?)s/&#8217;;<br />
$count = preg_match($regex, $head, $matches);</p>
<p>return isset($matches[1]) ? $matches[1] : &#8220;unknown&#8221;;<br />
}</p></blockquote>
<p>To use the function we could do something like this:</p>
<blockquote><p>$file=&#8221;http://img1.putpic.com/images/main/10/28719152288-orig.jpg&#8221;;<br />
echo remote_filesize($file);</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.incero.com/webdev/checking-remote-file-size-with-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

