PHP

Save your Site, Cache that Data!

One of the things that I’ve noticed in running PHPDeveloper.org is that the highest traffic (most of the traffic for the site, actually) is going to the RSS feed giving the latest news I’ve posted. When I first relaunched the site with Solar, things were fine – but only for about ten minutes. As soon as everyone’s aggregators came back on and started pulling the feed, the load on my server shot straight up. Thankfully I was able to get it back down to a more manageable level with a static version before the box took a nosedive. I had to do something about it and I figured that caching the feed’s information was definitely a start.

I’d never really used the Solar_Cache stuff before, but thankfully – it’s super easy. I figured that the biggest bottleneck in making the feed was pulling the data from the database each time. I opened up the controller for my feed (Feed.php – I know, very creative) and added a Solar_Cache object.

You can set this stuff up in your configuration file too, but I dropped it into my controller as a quick solution.

In my _setup() call:

$config=array(
    'adapter'=> 'Solar_Cache_Adapter_File',
    'path'=> '/tmp',
    'life'=> 200
);
$this->cache = Solar::factory('Solar_Cache', $config);

This creates a cache object in $this->cache that I can use for whatever I want. It’s file caching and the results will get put in /tmp. That “200” for the life is in seconds, so it’s at about three minutes right now. There’s lots more options for caching besides files already built into the framework too like APC, eAccelerator, variables and XCache.

With our object made, we apply it down in our default actionIndex() wrapped around our database fetch:

$ret=$this->cache->fetch('feed_data');
if(!$ret){
   $news=$this->news->fetchNews();
   $this->cache->save('feed_data',$news);
   $ret=$news;
}
$this->news_items=$ret;

Pretty simple, really – the cache object checks to see if the data already exists and, if it does, just passes it on through to our view. If it doesn’t (either that it’s the first time it’s being made or it has expired) it will pull the new news and push it out to the cache. The view then takes this array of values and makes a basic RSS feed out of it for all the world to see.

You wouldn’t believe how much something simple like caching your feed can help on even a moderately popular site. Check out the class list for details on the other caching options.

A Look Back from 10k

It’s funny – I only realized a few days ago that the 10k post was coming up. You get so used to just wring the posts day after day that you don’t even really notice the numbers. Each thousand along the way has definitely been a milestone, but reaching ten thousand posts to PHPDeveloper.org really feels like an accomplishment.

I started the site while I was back in college. A friend of mine at the time (who I now work with once again, woo!) introduced a young Perl programmer to the wild world of web programming. When I headed out to college I had a basic idea of how the web worked and what it was. I knew there was value in it and not just in the business sense. There was this feeling that I could put my fingers to the keys and make things – things other people could look at and enjoy. When I learned about PHP, my interest grew and I read everything I could and looked at every site even remotely related to PHP. The more I really got into it, the more I wanted to share the things I was finding with the whole web (or at least the part that would want to read it). So, in one late Texas summer, the phpdeveloper.org domain name was bought and I set up shop on a little 486 there on the school’s network….it pays to be friends with the network admins.

Back then I would only post once a day – it’d gather some of the things that I thought were useful and write a summary, mashing them all together. I worked on the site (then in PHP3) and used it as a learning experience to grow in the language. Terms like “CMS” and “abstraction” started to come into the picture and soon PHP4 burst onto the scene in a big way. The site got its first major rewrite then, adapting to this strange and new object oriented setup the language now offered. I created my own little set of libraries to use for the site and whatever other projects that bled over on the sites. The number of hits that the site was getting was growing and the little 486 had to be retired for a dual Celeron 266 machine in my apartment. It kept the room hot but it served up the pages well.

Fast forward to just a few years ago and you’ll find PHPDeveloper.org sitting on a dedicated server, graduating up to the “big boy” world. The site’s been through two more major rewrites (one with the Zend Framework and the other recently with Solar) and have moved hosts once again to where it lives now (Slicehost).

I’ve had tons of help from others in the PHP community out there over the years – people like Davey, Eric and Ben that have posted for me what I wasn’t even remotely close to an internet connection. There have also been lots of supporting players over the years and, more recently, people from the community offering suggestions and sending in news submissions and leads to follow.

PHPDeveloper.org has always been about sharing the best and latest from all around the web to the PHP developers out there and I have no plan of stopping any time soon. As long as the PHP community thrives (and lets face it, it’s not going anywhere) the site will be right there along with it with plenty of news, views and community thoughts as they happen.

Thanks to all for the support to make it to 10k – here’s to hoping for 10k more!

PHPDeveloper.org Sees the Light – The Move to Solar

So I’ve been asked several times about the move I made for PHPDeveloper.org from the Zend Framework over to Solar with the main question being “why?”

Well, I hate to break it to any of the framework zealots out there but the only real reason I had for doing it was the old “try something new” idea that floats around every so often. Yes, I know the site was working just fine under the old Zend Framework code (and yes, I do mean old – I think it was a few versions before 1.0 even) but I get the itch to do something new every once and a while. Some people redesign – I’ve done that too – and others rewrite things from scratch.

I took the opportunity to really look at the core of the site, stripping out all of the extra little “goodies” that I’d hacked in to the ZF version to get various things working. I came back to the primary focus of the site – to provide the latest news information quickly and easily – and made sure that all new code pointed toward that goal. The overall concept is a simple one really: it’s essentailly a blog whos topic just happens to be the goings-on of the PHP community as a whole. All it really needed to do was show the news items, serve up a feed and provide an administrative way for me to add new posts to the system.

I developed the Zend Framework version many moons ago and I almost don’t remember how it was all set up. It took me a bit to get back into it to see how things were structured, but in the end, most of that was tossed and replaced wth some sleek Solar code.

One of the biggest things that I was happy with in the new rewrite was the way that the news information is fetched from a the database. There’s no longer function calls like “getMainNews()” or “getNewsDetail()”. Instead they were replaced by a fetch function that takes in parameters on the object (sort of like the Command design pattern) and applies them to the current query.

For example, I make a call to the “setProperties” function of the NewsAPI object to tell it that I want a type of “where” with a value of “ID=1234”. The fetch function then looks through the properties and applies the operation to the query. The result is a function that can be called the same way every time with the same sort of output. The only difference is in how much/what kind of output there is.

I was concerned about some of the performance issues I was seeing on my server when I made the switch. Some of it was my own fault – forgetting to cache the feed instead of geenrating it, not adding the spam/IP filtering to ward off some of the spammers – but there was still a slow down when the load started to get high. I knew Solar could handle it (it had done it wonderfully on the dev server) so it had to be something else. The dedicated machine I’d been using was nice, but was showing some of its age. I decided to buy a slice from Slicehost and set up shop over there with only PHPDev running on it. Turns out that it wasn’t the new Solar version that was the issue, it was the server. In fact, I’d almost be willing to not cache the feed anymore – the performance is that good.

My last little part of the transition is writing the backend command-line scripts that I use to do some automatic things and the site will be back and complete and 100% Solar-ized.

I know there’s some things I didn’t cover here, so if you have any questions, leave a comment or drop me a line: enygma at phpdeveloper dot org. I’m more than happy to talk Solar with you. And if you’re interested and want to chat with other Solar folks (including some of the main developers behind it), come over to the freenode network – irc.freenode.net – and pop in to #solarphp and say “hi”.

SolarPHP.com

Running a remote script over ssh from EditPlus

I came up with something handy for EditPlus users out there who might need to execute something on a remote machine (like say the linux box that has the samba share your files are being accessed throught).

My situation is that we use templating on all of our files that needs to be regenerated each time there’s a change made. Previously, this meant having two windows open – one for EditPlus and another that’s a ssh session at the directory you’re working with. Well, in one of those “surely there’s a better way” moments this morning, I did some digging and came up with this process:

– Using the “user tools” in EditPlus, create a connection to a remote machine
– via plink (Win) to ssh to the machine
– and execute the command over that interface

#mylist li { margin: 5px; }
Well, it look a little PHP trickery to get it working exactly right, but here’s how:

  1. Download plink
  2. In EditPlus, go to Tools -> Configure User Tools
  3. Hit “Add” and choose “Program”
  4. Change the program name (in the “Menu Text”) to your liking
  5. Add the command to execute in the Command box.
    In my case, I wanted to connect to the remote machine over ssh and run the command to retemplate the file I was working on. Here’s what I put:

    plink.exe user@server -pw mypass /usr/local/bin/retemp.php
  6. Add an argument
    I put the value of ‘$(FilePathNoDrv)’ in there (yes, with the quotes) to append the path to the file without the drive letter
  7. Click “Capture Output” and “Save open files”
  8. Hit “Ok” to save the changes

Then you can check your Tools menu to see what the keystroke for it is and voila – you’re all set. It’s nice that it gives the option to save the file when you execute the tool. Anything that makes for less keystrokes for me!

The PHP script on the other side had to do a little something to handle EditPlus’ input correctly – here’s the example:

#!/usr/local/bin/php

$in=file_get_contents("php://input");
exec('/usr/local/bin/template.sh /www/web/'.str_replace('\','/',$_SERVER['argv'][1]),$out);
//print_r($out);

I left that $out in there just in case you might need to have some debugging output. Because of the way that the script passes in the values (it is a Windows software after all), we have to switch around the slashes to work with the linux file system. So, if in EditPlus my path is like H:wwwdocrootmyfile.tpf the script will map it over to /www/docroot/myfile.tpf and run the template.sh on it to retemplate it.

There we go – hope it’s helpful!

Being Binary in SOAP

Well, it might not be the best way to do it, but here’s a way I found to send binary data via PHP’s SOAP extension from one place to another:

Server:

function recieveFile($data){
	$data=base64_decode($data);
	$path='/my/file/path/img_out.gif';
	$fp=fopen($path,'w+');
	if($fp){ fwrite($fp,$data); fclose($fp); }

	return strlen($data).' written';
}
$input	= file_get_contents("php://input");
$server = new SoapServer(
	'http://[my url here]/binary.wsdl',
	array('encoding'=>'ISO-8859-1')
);
$server->addFunction('recieveFile');
$server->handle();

and the Client:

ini_set("soap.wsdl_cache_enabled", "0");

//send binary data
$client=new SoapClient(
	'http://[my url here]/binary.wsdl',
	array('encoding'=>'ISO-8859-1')
);

$data=file_get_contents('/my/file/path/img_to_send.gif');
$ret=$client->recieveFile(base64_encode($data));
print_r($ret);

It’s pretty basic – the client just reads in the file’s information, runs it through a call to base64_encode before it’s sent off to the server. Once it’s there a mirror call to base64_decode gets the content back to normal and it’s written out to the “img_out.gif” file on the remote server.

It’s probably not the best way to do it, but its one that I’ve found that works quickly and easily. I tried to just send the binary data without base64 encoding it and it didn’t want to cooperate (it was only getting the first chunk of data). I don’t know how well it’ll perform with larger files, though – we shall see.

My Day of Advent – Dec 10th

Lookit! It’s me!

Chris has posted my contribution (self-promotion?) to the Advent Calendar for this year – my (not so brief) look at planning your applications. Thanks to Chris for including me on the list for this year’s calendar (there’s going to be more, right?)

I got to try out the new photo editing in Flickr to make the picture for it – works pretty well for being web-based.

In the way of a personal plug, besides the holiday themed calendar version of each of the days that Sean’s created, I’ve also been keeping up with each of them in a post over on PHPDeveloper.org.

Some “Why Won’t Solar Work” Tips

With more and more people installing and using Solar all the time, theres some questions that get asked quite a bit. I wanted to help with some of those questions by providing some simple answers here. Here we go…

  • Tip #1 – Be sure that you have your App directory correctly set in the configuration file. If you don’t add it to your front controller Classes setting, Solar has no idea where to find it.
  • Tip #2 – Class names on the controllers are important! Be sure it follows the directory tree like Project_App_Controller. Also be sure you’re extending the right thing. I usually use a Base controller/setup to provide an overarching “global” place to put things (like a layout) and extend that, so it’s usually “extends Project_App_Base”
  • Tip #3 – You can change the values that the Solar_Form login functionality uses to trigger the automagic login process by setting it in the adapter for your authentication object (like a Solar_Auth_Adapter_Sql) via the process_login and process_logout values.
  • Tip #4 – Be sure to include everything you need to get to “magically” through Solar in the set_include_path in the front controller. For example, you can add in another directory with external libraries so that in your application, you can just call it and let the __autoload handle it.
  • Tip #5 – You might get some complaints from Solar about not having a “sql” object it can work with. I good way to handle this is to check in your _setup function of your controllers to see if there’s one registered. If not, make one with a factory call and register it for the framework’s use: Solar_Registry::set(‘sql’, Solar::factory(‘Solar_Sql’));

Book Review: PHP Oracle Web Development

I recently received another one of Packt Publishing’s PHP-related offerings that’s targeted at more than just the PHP programming population. Their “PHP Oracle Web Development” seeks to be a sort of crossover book – take one part PHP, one part Oracle database work and toss together to make an interesting mix.

The book is laid out simply enough:

  • Getting started with PHP and Oracle
  • PHP and Oracle Connection
  • Data Processing
  • Transactions
  • Object-oriented Approach
  • Security
  • Caching
  • XML-enabled Applications
  • Web Services
  • AJAX-Based Applications
  • and an appendix showing how to install the PHP and Oracle software on different OSes.

Overall, the book is well-written – there were a few places where I don’t know if I agree with how they presented the material (somewhat confusing), but at least it was there. I like that they have a range of topics covered in the book – unfortunately, this is also one of the bad points about it. Since they did try to appeal to both the Oracle developers learning PHP and the PHP developers looking to learn how to work with Oracle, they didn’t get much of a chance to really dig into some of the fun things below the surface. After the first few chapters, you could basically replace the Oracle-ness in the examples with a lot of the other database systems out there (MySQL, PostgreSQL, etc) and you wouldn’t have to change much.

The book became more of a “just another PHP projects” book by focusing on things that could be done with any other system out there. I wanted to see more of an Oracle focus, maybe looking more at things like installing the updated PDO drivers for the OCI8 connection or suggestions on tuning the actual connection between the script and the database. There’s also almost no mention of working with settings on the database side to optimize anything for the connecting script.

Overall, I’d recommend this book to a certain audience – ones just starting out working with the PHP/Oracle combination. I passed it around to a few of the database developers here that work with PHP some and they found that most of the material covered in the book wasn’t anything you couldn’t learn from five minutes of googling when you had a question. It is good, though, to have as a “first guide” if you’re not familiar with the territory.

http://rcm.amazon.com/e/cm?t=phpdorg-20&o=1&p=8&l=as1&asins=1847193633&fc1=000000&IS2=1&lt1=_blank&lc1=0000FF&bc1=FFFFFF&bg1=FFFFFF&f=ifr

Wanted: Developers (but who are they?)

So, because of PHPDeveloper.org, I get lots of emails (more recently lately) about people looking for skilled PHP/MySQL/Apache/etc developers to help them with projects. They’re not really recruiters from what I can tell, but they do seem to be in need of some names to give a call.

My question for you all is – what do you normally do with these sorts of emails? Since I don’t really have a good resource to look at an recommend people from, I usually just end up telling them that I don’t know of any offhand. I’d love to be able to turn around and give them a list of names, though, to help out others in the PHP community.

Does anyone out there have a good resource for this? Is this something that the PHP community might be in need of? I know there’s lots of job boards out there, but would something more tailored to PHP be called for?

buy viagra
buy viagra online
viagra online
cheap viagra
herbal viagra
female viagra
viagra for women
free viagra
viagra side effects
viagra alternative
viagra alternatives
natural viagra
order viagra
alternative to viagra
discount viagra
free viagra samples
order viagra online
best price viagra
cheap generic viagra
online viagra
viagra cheap
free viagra sample
viagra generic
viagra 6 free samples
alternatives to viagra
viagra on line
viagra price
viagra jokes
viagra pills
viagra canada
cheap cialis
buy cialis
cialis online
cheapest cialis
discount cialis
cialis side effects
order cialis
cialis drug
cialis forum
cheap generic cialis
cialis and levitra
cilia structure
cialis viagra
cialis cheap
buy cialis online
cialis vs viagra
cialis samples
free cialis
cialis soft tabs
cialis generic viagra
cialis tadalafil
cialis generic
cialis online discount
levitra vs cialis
cialis dosage
cialis uk
cialis free sample
purchase cialis
buy viagra
buy viagra online
viagra online
cheap viagra
herbal viagra
female viagra
viagra for women
free viagra
viagra side effects
viagra alternative
viagra alternatives
natural viagra
order viagra
alternative to viagra
discount viagra
free viagra samples
order viagra online
best price viagra
cheap generic viagra
online viagra
viagra cheap
free viagra sample
viagra generic
viagra 6 free samples
alternatives to viagra
viagra on line
viagra price
viagra jokes
viagra pills
viagra canada
cheap cialis
buy cialis
cialis online
cheapest cialis
discount cialis
cialis side effects
order cialis
cialis drug
cialis forum
cheap generic cialis
cialis and levitra
cilia structure
cialis viagra
cialis cheap
buy cialis online
cialis vs viagra
cialis samples
free cialis
cialis soft tabs
cialis generic viagra
cialis tadalafil
cialis generic
cialis online discount
levitra vs cialis
cialis dosage
cialis uk
cialis free sample
purchase cialis
buy adipex
adipex diet pill
buy adipex online
adipex effects
order adipex
alprazolam 25mg
buy alprazolam online
buy alprazolam
order alprazolam
what is alprazolam
ambien 10mg
ambien purchase
buy ambien online
buy ambien
order ambien
ativan detox
ativan dosage
ativan info
buy ativan
order ativan
advance cash loan
advance cash
cash advance america
cash advance loan
cash advance payments
buy cheap fioricet
buy fioricet
cheap fioricet
discount fioricet
order fioricet online
cheap hydrocodone
generic hydrocodone
hydrocodone dosage
norco hydrocodone
online hydrocodone
buy levitra
cheap levitra
discount levitra
generic levitra
purchase levitra
buy meridia
cheap meridia
discount meridia
generic meridia
meridia drug
advance cash loan
bad credit bank loans
bad credit home loans
bad credit loans
quik payday loans
phentermine overnight
buy phentermine
cheapest phentermine
discount phentermine
online phentermine
cell phone ringtones
cheap ringtones
download ringtones
free nokia ringtones
samsung ringtones
buy soma online
cheap soma
discount soma
order soma
soma pill
adipex tenuate
buy tenuate
cheap tenuate
order tenuate
tenuate overnight
100 tramadol
about tramadol
cheap tramadol fedex
tramadol 50mg
tramadol online
order ultram
pain ultram
ultram detox
ultram dosage
ultram pill
buy valium online
cheap valium
valium prescription
valium 10mg
valium overnight
buy vicodin
cheap vicodin
order vicodin
purchase vicodin
vicodine online
buy vicodin
cheap vicodin
order vicodin
purchase vicodin
vicodine online
alprazolam xanax
ativan xanax
buy xanax
cheap xanax
xanax dosage
buy adipex
adipex diet pill
buy adipex online
adipex effects
order adipex
alprazolam 25mg
buy alprazolam online
buy alprazolam
order alprazolam
what is alprazolam
ambien 10mg
ambien purchase
buy-ambien online
buy ambien
order ambien
ativan detox
ativan dosage
ativan info
buy ativan
order ativan
advance-cash loan
advance cash
cash advance america
cash-advance loan
cash advance payments
buy cheap fioricet
buy fioricet
cheap fioricet
discount fioricet
order fioricet online
cheap hydrocodone
generic hydrocodone
hydrocodone dosage
norco hydrocodone
online hydrocodone
buy levitra
cheap levitra
discount levitra
generic levitra
purchase levitra
buy meridia
cheap meridia
discount meridia
generic meridia
meridia drug
advance cash loan
bad credit bank loans
bad credit home loans
bad-credit loans
quik-payday loans
phentermine overnight
buy phentermine
cheapest phentermine
discount phentermine
online phentermine
cell phone ringtones
cheap ringtones
download ringtones
free nokia ringtones
samsung ringtones
buy-soma online
cheap soma
discount soma
order soma
soma pill
adipex tenuate
buy tenuate
cheap tenuate
order tenuate
tenuate overnight
100 tramadol
about tramadol
cheap tramadol fedex
tramadol 50mg
tramadol online
order ultram
pain ultram
ultram detox
ultram dosage
ultram pill
buy valium online
cheap valium
valium prescription
valium 10mg
valium overnight
buy vicodin
cheap vicodin
order vicodin
purchase vicodin
vicodine online
buy vicodin
cheap vicodin
order vicodin
purchase vicodin
vicodine online
alprazolam xanax
ativan xanax
buy xanax
cheap xanax
xanax dosage

ZendCon07 Comes to a Close

Well, the party’s over – the booths have been packed up, the X-Boxes put away and most of the attendees have already scattered back towards which ever of the four corners of the world they arrived from. Happily, things seemed to go really well this year and overall, I feel like it was a better conference than the previous years.

Things seemed to flow well – the sessions were easy to find and were usually full up with eager developers wanting to glean what they could from the talk. A great range of topics was presented – here’s just a small list:

  • API Development
  • PayPal’s developer offerings
  • memcached
  • PHP Security
  • mobile application development with PHP
  • High performance MySQL tips
  • Unicode (because, after all, what PHP conference these days would be complete without a talk on this)
  • DateTime
  • Agile development

And that’s not even the half of it – there were around fifty-five talks in all presented over three days (including the tutorials on the first day). Thankfully, for those that weren’t able to attend, the folks over at the Zend Developer Zone will have podcast recordings (and slides too, I think) of each of them posted soon.

I also want to make mention of someone who played a big part in helping make sure things came together both before and during the conference this year – Cal Evans. His daily duties included not only being the MC for the event, but also more behind the scenes magic that helped the whole event come off so well. The best part about it all was that, despite the Zend duties that he always had to attend to, he always had the time to stop and work with the people in the community – even if it was just to stop off and connect two people (“you gotta meet this guy…”).

The hotel was nice and the events in the evenings were a nice chance to mingle with ther developers in a bit more informal setting (oh, and Yahoo – maybe not so much with the comedian and magician next time around). There were a few things that I imagine couldn’t be helped too much (the quality of the service at the hotel, the coordination of the vegetarian meals), but they didn’t distract too much from the overall feel of the conference.

Here’s hoping to see you all next year (and hoping I get to come! heh)