Archive for the ‘PHP’ Category
Thursday, July 24th, 2008
In order to do some of our tutorials (or program with PHP and MySQL in general) you need to be able to run PHP and MySQL. Although most free hosts do not have PHP and MySQL support there are some that do, and there are also many low cost hosting options available. If you already have hosting and are unsure if you have PHP and MySQL support you should contact your host directly. If you are shopping for hosting be sure that they support PHP and that your package includes at least one MySQL database.
Another option is to install PHP and MySQL directly onto your Windows computer. If you are a Mac user you already have the capability and just need to activate PHP and MySQL.
Tags: activate, Although, capability, Computer, database, Directly, MySQL, package, PHP, running, support, windows
Posted in MySQL, PHP, tricks | No Comments »
Thursday, July 24th, 2008
PHP is a scripting language that is often imbedded into HTML to add functions HTML alone can’t do. PHP allows you to collect, process and utilize data to create a desired output. In short, it let’s you interact with your pages.
PHP is able to preform a number of tasks including printing data, making numeric calculations (such as addition or multiplication), making comparisons (which is bigger, are they equal, etc) and making simple boolean choices. From this you can create more complex loops and functions to make your page generate more specialized data.
Tags: bigger, calculations, functions, html, loops, multiplication, numeric, output, PHP, scripting language
Posted in PHP, tricks | No Comments »
Thursday, July 24th, 2008
PHP and MySQL combine to be an easy yet powerful way to create dynamic web pages that actually interact with your visitors. HTML can create useful and well formatted web pages. With the addition of PHP and MySQL you can collect data from your users, create specific content on the fly, and do many other things that HTML alone can’t do.
The beauty of PHP as a language is that it is designed to be used along with HTML. You can use PHP right inside your already existing HTML content, or put HTML tags right inside your PHP coding. When learning PHP you are not making your existing HTML knowledge obsolete, you are instead adding to it to give it more functions and abilities.
Tags: abilities, collect, designed, html, knowledge, learning, MySQL, obsolete, PHP, users, web pages
Posted in MySQL, PHP, tricks, web designing | No Comments »
Tuesday, July 15th, 2008
Finally lets look at modifying the environment. I actually cheated here and just set the max execution time to 60 seconds a million times. I think the result is still valid though
ini_alter vs ini_set
ini_alter: 103.332370043 seconds
ini_set: 86.2883789539 seconds
Time saved: 17.0439910889 seconds; 19.7523598143%
As might be expected these functions are expensive when it comes to execution time. That 17 microsecond saving is massive as well making ini_set the superior choice.
Tags: alter, execution, expensive, microsecond, modifying, PHP, seconds, time, vs
Posted in PHP, tricks | No Comments »
Tuesday, July 15th, 2008
This one really surprised me. I expected these functions to be faster. Both these functions allow you to convert an array into a string. implode is the opposite of explode and join allows you to join the items in an array with a ‘glue’ string. In this case the array had 100 items.
implode vs join
implode: 47.2712550163 seconds
join: 50.1287050247 seconds
Time saved: 2.85745000839 seconds; 5.70022705949%
5% doesn’t seem like all that much but 2 microseconds shouldn’t be ignored.
Tags: explode, faster, functions, glue, implode, items, join, PHP, seconds, String
Posted in PHP, tricks | No Comments »
Monday, July 14th, 2008
So far all the functions have been running fast anyway so the difference haven’t been that significant but things are starting to get interesting with the run time jumping to 20-24 microseconds to write a short string to a file.
fwrite vs fputs
fwrite: 24.9826359749 seconds
fputs: 20.1990799904 seconds
Time saved: 4.7835559845 seconds; 23.6820488199%
With a difference of over 4 microseconds you could run both fputs and floatval in the time it takes to run fwrite. The difference is over 23% which clearly makes fputs the better function. It’s shorter as well.
Tags: Anyway, difference, File, functions, interesting, microseconds, running, shorter, significant
Posted in PHP, tricks | No Comments »
Monday, July 14th, 2008
Both these functions allow you to quickly pick a float, or double, out of a string.
doubleval vs floatval
doubleval: 4.56571412086 seconds
floatval: 4.35375285149 seconds
Time saved: 0.211961269379 seconds; 4.8684727087%
4% or 211 nanoseconds is next to nothing. I would want to use floatval but I wouldn’t exactly be kicking myself if I slipped a doubleval into my code instead.
Tags: doubleval, floatval, Instead, kicking, myself, nanoseconds, next, nothing, PHP
Posted in PHP, tricks | No Comments »
Monday, July 14th, 2008
Tidying up a string breaks the pattern. Maybe my analysis was a little premature.
chop vs rtrim
chop: 4.73731994629 seconds
rtrim: 4.41647195816 seconds
Time saved: 0.320847988129 seconds; 7.26480301852%
rtrim is a little faster and these functions take longer at a little over 4 microseconds.
Tags: chop, faster, functions, little, microseconds, PHP, rtrim
Posted in PHP, tricks | No Comments »
Monday, July 14th, 2008
Next it is time to try some validation with is_int and is_integer.
is_int vs is_integer
is_int: 3.11394786835 seconds
is_integer: 3.42630600929 seconds
Time saved: 0.312358140945 seconds; 9.11646946006%
The difference is smaller this time but again both functions are executing in a little over 3 microseconds. is_int is faster than is_integer so again the shorter function name wins. Is this going to be a pattern?
Tags: again, difference, functions, integer, microseconds, pattern, PHP
Posted in PHP, tricks | No Comments »
Monday, July 14th, 2008
First up are the sizeof and count functions. They can both be used to count the number of items in an array but does one do it better?
sizeof vs count
sizeof: 3.75928902626 seconds
count: 3.33035206795 seconds
Time saved: 0.428936958313 seconds; 12.8796280262%
The evidence says yes. The count function was over 12% faster in this test. Both functions are fast though taking 3-4 microseconds to count an array with 100,000 items. You might think it isn’t worth it but remember count is also a character shorter. Not only is it faster to run but it is also faster to type!
Tags: array, character shorter, count, evidence, fast, faster, functions, number, PHP, remember, sizeof
Posted in PHP, tricks | No Comments »