Optimizing a php application in 5 minutes
It is often said that premature optimization is the root of all evil: it is indeed true that the optimization stage must come after the main development of an application has been completed. Optimizing means reducing loading and execution times, improving the user experience by making the application reacting more responsively.
When it comes the time to optimize your web application, don’t go blindly searching for the bottleneck. Often there are no obvious improvable points in a codebase and your assumptions about the slowness causes can be wrong. Profiling is the activity of discovering what is forcing your application run slower than expected, by analyzing the code execution and time tracking.
If your language of choice is php, fortunately this process takes only 5 minutes.
Read more…
Securing PHP webservers
PHP applications have a reputation for higher than average security problems. What configuration techniques do you use for making sure the application is secure as possible ?
I’m looking for ideas like:
- Using Hardened PHP/Suhosin
- Using mod_security
- Disabling register_globals and allow_url_fopen in php.ini
I normally use Linux, but feel free to suggest Windows solutions too.
By David Pashley?
Install mcache (msession) to be used for session caching in PHP
Installing mcache, previously known as msession, on CentOS 32 bit system.
MCache can be used completely transparently to a PHP application. By editing PHP’s “php.ini” file to use MCache as its default session handler (see Appendix D), applications will simply use MCache without knowing. This has an advantage in that MCache presents a standard interface for PHP regardless of it storage configuration. It can even hide which storage system or database is used and provides an amount of connection pooling and SQL caching.
If you are on 64 bit system, you will get errors, lots of them. Following instructions work fine with 32 bit systems. For more help look at the MCache Handbook.
Web site: http://www.mohawksoft.org/?q=node/32
PHP reference: http://us2.php.net/manual/en/ref.msession.php
Read more…
Stop PHP nobody Spammers
PHP and Apache has a history of not being able to track which users are sending out mail through the PHP mail function from the nobody user causing leaks in formmail scripts and malicious users to spam from your server without you knowing who or where.
Watching your exim_mainlog doesn’t exactly help, you see th email going out but you can’t track from which user or script is sending it. This is a quick and dirty way to get around the nobody spam problem on your Linux server.
If you check out your PHP.ini file you’ll notice that your mail program is set to: /usr/sbin/sendmail and 99.99% of PHP scripts will just use the built in mail(); function for PHP – so everything will go through /usr/sbin/sendmail =)
Requirements:
We assume you’re using Apache 1.3x, PHP and Exim. This may work on other systems but we’re only tested it on a Cpanel/WHM Red Hat Enterprise system. Read more…
Rotating Banner in PHP
This is a snippet that will rotate a banner on a page. All you have to do is set $File and $Images to the paths to the images. It will just do the next image in $Images in order. It doesn’t rotate banners for seperate users, it just goes through. Before you use it, create the $Stat file and set the contents of it to 0 and your ready to go!
Read more…
Text counter in PHP
A counter is an essential part of a site to know how many people are coming to site. Here is an easy way to make a counter. All you need is access to PHP and be able to chmod a directory. We’re going to save the amount of hits in a .dat file, so you don’t even need a mySQL database. First off, you have create a directory and CHMOD it 777 so PHP can write the counter.dat file.
Here is what we have to do:
- Use the file_exists() function in PHP and see if the counter.dat file exists. If it does, then open the file using the PHP fopen() function.
- Use the PHP fgets() function to find the number of hits there and save it in a variable.
- Add one to the variable.
- Close the file.
- Display the number of hits.
- Open the counter.dat file using the fopen() function and save it as a variable.
- Use the PHP fputs() function to insert the new number of hits.
- Close the file.
- If the counter.dat file doesn’t exist, then use the fopen() function and declare it as a variable.
- Use the Fputs() function and put a “1″ in there.
- Print out that 1 person has come to the page and then close the file.
Here is the code: Read more…
Create Random Text in PHP
Want to put a random quote on your site? Or randomize some other aspect of your site? It’s easy. You’ll want to use PHP or some other server-side scripting language instead of a client-side scripting language like JavaScript. Server-side languages write the content to the page in html before it ever leaves the server. Search engines will be able to read the content on your page, but with JavaScript they cannot, so you lose any content value of the random code. Also, if a user turns off JavaScript, that random content is lost. Google, MSN, and Yahoo will see that the content is changing often, and that may help your rankings (depending on your implementation).
Here’s how to put the random elements into your page, using PHP.
Step 1:
Create a text file called ‘myData.txt’. Open the file and put in your random elements, placing each random element on its own line, (whether text, images or html). Then place ‘myData.txt’ in the same directory as your page containing the PHP script.
Step 2:
Place the following PHP code into your page where you want the random element:
Read more…
Installing Lighttpd With PHP5 Support On CentOS
Lighttpd is a secure, fast, standards-compliant web server designed for speed-critical environments. This tutorial shows how you can install Lighttpd on a CentOS 5.0 server with PHP5 support (through FastCGI) and MySQL support.
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
Afterwards, we can install Lighttpd like this:
yum install lighttpd Read more…
How To Install IonCube Loader
If you need IonCube loader in order to encode scripts. You will need to install IonCube loadar on your box.
- Login to your server as root and download the loaderfor your server: http://www.ioncube.com/loader_download.php
- Then extract it
tar -zxvf ioncube_loaders.tar.gz
cd ioncube - Copy ioncube-install-assistant.php file to a www diretory
cp ioncube-install-assistant.php /home/username_here/www
How to run PHP 4 and 5 on Cpanel
by Tweak on June 13, 2009
in Domain/Hosting, Php, Servers
This information is helpful for hosting companies that want to run PHP 4 & 5 on the same cPanel server. After this, Hosting costumers / cPanel users should choose what version of PHP will they use on theirs scripts.
You should consider some implications on your server performance, but webhosts are using because they don’t need two server to run the different PHP versions for different costumers.
How to run PHP 4 and 5 on the same Cpanel server
Read more…