Archive for the ‘PHP and MySQL’ Category

PHP and MySQL are core pieces of software primarily used for web development. They are often paired with Linux and Apache resulting in a configuration called LAMP (Linux Apache MySQL PHP).

PHP and MySQL are not only solid, but open-source which is easy on developers, and they are relatively simple which is wonderful for developers.

PHP is a double-redundant acronym, standing for Personal Home Page Hypertext Processor

PHP Snippet: Copyright Date

Here is a quick PHP snippet to show the copyright date and keep it current. Starting next year, it will display the year range, such as 2011-2012. However, for the current year, it will only display 2011.

It’s almost as easy as copy-and-paste, there is just one extra step:

  1. Copy-and-paste the code into your page
  2. Set $startYear manually to the current year.

(more…)

MySQL: Increasing performance of keyword searching – Fulltext vs. Sphinx

MySQL thankfully has a built-in data type called “FULLTEXT”.

For a long time, it did not have a native keyword search engine (ie. natural language search). We’ve seen a lot of functionality become easier and more standard thanks to the introduction of FULLTEXT several years ago.

With a MySQL FULLTEXT column, all words greater than a certain length (default: 3 characters) are included in a keyword index. Some very common words are excluded. MySQL keeps a very efficient index of these keywords, and searching these fields can be much faster than using a LIKE or LOCATE() command.

To search a FULLTEXT column, you must use the MATCH AGAINST clause in MySQL:
MATCH (columnA, columnB) AGAINST ("keyword keyword2") (more…)

PHP: error reporting and display settings for my web application

PHP error reporting can be simple or difficult depending upon your application. Many sites and applications change the settings, either via the php.ini file, an .htaccess file, or directly in the PHP code. In fact, setting the values directly in the PHP code of your application is probably the most common method.

So which settings are you actually supposed to change? Try these for starters:

  • error_reporting
  • display_errors
  • log_errors

The following example contains the syntax:

ini_set('error_reporting', E_ALL & ~E_NOTICE);
ini_set('display_errors', 0);
ini_set('log_errors', 1);

(more…)

PHP & Perl: How do I redirect all output from STDOUT or STDERR into a file?

The power of PHP often goes without question, however once in a while we remember a little something from Perl that we just wish was as easy in PHP. The truth is, so much is easier with PHP than with Perl that PHP is just awesome, but hey – it’s a programming language – it’s going to have shortcomings. The most common reason we are asked this is for crons – scheduled programs, batches, and such. Often a programmer will want to redirect the output to a certain file, or to /dev/null. In Perl, you are able to do this easy-as-cheese:

open (STDOUT, ">/path/to/file") or die "Can't redirect STDOUT: $!";

open (STDERR, ">>/path/to/file") or die "Can't redirect STDERR: $!";

Please take note: PERL redirects a filehandle in one line!

However, PHP is a bit of a different story: (more…)

Mobile Standards: Web Development and Programming – HTML, CSS and JavaScript

“Mobile standards” cropped up several years ago, but even today there is a struggle to gain following. There is a vague overall definition, as various different pieces of web development have taken different approaches.

First of all, your HTML web standards remain the same, although you can find a variety of extra possible settings (Google Search: Mobile Doctype). You can leave your website in it’s current HTML form and allow the mobile browser to resize it accordingly, or you can “detect” when a mobile user is accessing a page, and server up a custom mobile-friendly page. Even if you choose the simple approach and just let the mobile browser work it’s magic, you will probably need to make some minor adjustments anyway too your website’s layout, font sizes and a few more things. (more…)

How do I find a good web developer or programmer?

Getting good web developers anywhere in the world is tough. If you are located on the west coast, California, you are lucky – and spoiled. California has spawned web developers and programmers that are really talented, and they have infiltrated much of the west coast and beyond. If you are willing to hire a developer, try to find one who is from the west coast – they have probably been around the block. Silicon Valley (yada yada) has helped to spread all kinds of development talent around: game developers, web developers, robotic programmers, HTML and CSS gurus – and more – the whole gamut.

Finding a good developer can be easy or difficult – it’s usually up to you. Many people looking to hire a web developer have such a poor understanding of the task at hand. Many of these people also have a poor understanding of what the project will involve, the timeframe, and most importantly – the culture of developers. Look for developers who have been around quite a while. Look for ones with medium-range jobs, you don’t want the NASA engineer of web programming – but you also don’t want the line cook of web development. There is a “sweet spot” in the middle, where experience and efficiency meet your needs and budget – and all is good in the world.

Also, don’t try to pay people to complete small projects for a couple hundred bucks at a time. Programmers hate trying to spec out a $200 feature. Once you find the right developer, hire them for the long term.

HTML 5 – a new standard to make your life more difficult

HTML 5. CSS 3.

We’ll say it to get it out of the way: it’s a move in the right direction.

That’s all the good credit we will give to it. From there on out, does it really make your life easier or better? does it help sites or do anything you can’t already do?

Developers were running crude versions of AJAX – an ancestor of AJAX in which you would basically use JavaScript to communicate with your server real-time, but this worked via simple HTTP, and there wasn’t much to it.

AJAX evolved and introduced a whole new level of pain and difficulty for developers.Manipulating the DOM in a cross-browser compatible fashion, oh yeah – remember what your mom used to say about raising you? “easier said that done”.

Up to the present, we’ve seen just about every AJAX library, PHP/MySQL framework, Drupal, Joomla, yada-yada-yada. So what does HTML 5 really mean for anyone? What does HTML 5 mean for my business? What does HTML 5 mean for my website? Is HTML 5 going to cost me money? Is it hard to find developers that can produce content in HTML? Will HTML 5 really be faster than Flash? Is my LAMP framework compatible with HTML 5? And ultimately, will upgrading my site to HTML 5 be worth it, and when should I upgrade to HTML 5?

Wow, that’s a lot of questions, we can’t answer that. But what we can do is give you an idea of what to expect: (more…)

How to fix your website’s performance problems – the secret guide

Database overloaded? High server load in general? Server stops responding for a few seconds at a time during high traffic periods, or crashes completely once in a while?

Here is the magic elixir for you!

The secret has been passed down to us through hundreds of generations, our ancestors gave their lives to find the secret. It’s truly is the ancient chinese secret. Mixed with a little spanish fly.

So what’s the secret to fixing your server’s performance problems? It’s to fix you’re server’s performance problems.

Yes, you read right.95% of the time when people need to fix their performance problems, this is what happens

1) They correctly diagnose the problem
2) They incorrectly go about solving it

You have to fix the actual source of the problem, rather than trying to control the side effects. Most developers can diagnose the problem without too much fuss, because if they can get FTP or SSH working, usually they are somewhat competent. Solving it is another story.

So how do you go about fixing the problems? We can’t tell you, but we can guide you – nudge you in the right direction just a bit.

(more…)