PHP

Linux Server Optimization Guide

This is a small guide on how to optimizing a linux server for performance, so that you can extract the full juice of your server. A lot of times, the default configurations are bad, and work slow- especially they matter a lot when you have low ram.

Python vs PHP (webdev)

Python and PHP are two different awesome programming languages, but often there is fight between developers following the two languages that one is better than other, etc.
I am publishing some astonishing benchmark results on Python-WSGI and PHP hello world scripts which makes no sense but still proves that Python is faster than PHP.

Animated buttons with JQuery in HTML+JS, from PHP

This article will show you how to do animated buttons (created in photoshop / gimp), with the text on the button as pure HTML..
One page can sport many different animated buttons, artwork is re-used and cached browser-side..

Apache2-PHP-FastCGI-SuExec

Yeah this is one of the most irritating type of thing to setup. I had a tough time with this, but ultimately got it right after a lot of researching.

Follow this tutorial and you'll successfully set the environment up - PHP running via FastCGI within an SuExec Environement in Apache 2 !

So lets start with a case study.

Even been keen on Learning PHP?

Tags:

Learning PHP just got a little more easier when the E-book has been introduced.

Get it free

50 Extremely Useful PHP Tools

Tags:

PHP is one of the most widely used open-source server-side scripting languages that exist today. With over 20 million indexed domains using PHP, including major websites like Facebook, Digg and WordPress, there are good reasons why many Web developers prefer it to other server-side scripting languages, such as Python and Ruby.

Sure, PHP isn’t quick, but it is the most used scripting language in practice; it has detailed documentation, a huge community, numerous ready-to-use scripts and well-supported frameworks; and most importantly, it’s much easier to get started with PHP than with other scripting languages (Python, for example). That’s why it makes perfect sense to provide the huge community of PHP developers with an overview of useful tools and resources that can make their development process easier and more effective.

This post presents 50 useful PHP tools that can significantly improve your programming workflow. Among other things, you’ll find a plethora of libraries and classes that aid in debugging, testing, profiling and code-authoring in PHP.

libphp5.so on Apache 2 is faster than CGI or FastCGI

Why this site loads so fast ? The reason is we are using Apache 2.2.10 with libphp5.so

Earlier we were using CGI.

I also tried PHP-FastCGI

Generating Serial Page Numbers in PHP [Pager]

Hello friends,

In this tutorial we explain how to generate page numbers serially and store them in a file called pages.html

You can further use this tutorial to implement this technique in your CMS [if you are building one :D]

In this tutorial we count the no. of articles in the database and divide it by 5 which implies that we display 5 articles per page. (we take intval() of the result).

This code will generate page nos as

Page 1

Page 2

....so on

Enjoy!

The code:

 

<?php

$db = mysqli_connect("localhost","user","password","database");

if ( mysqli_errno($db) ) {

die(mysqli_error($db));

}

$count = mysqli_query($db,"SELECT COUNT(*) FROM content");

if ( mysqli_errno($db) ) {

die(mysqli_error($db));

}

$r = mysqli_fetch_row($count);

$pg_no = intval($r[0]/5);

$htmlfile = fopen("pages.html", "w") or die("Error occurred while opening file");

for ( $i = 0; $i != $pg_no; $i++ ) {

$str = "<a href=home.html?p=".($i+1).">Page ".($i+1)."<br>";

fwrite($htmlfile, $str);

}

fclose($htmlfile);

print "\n";

?>

Adding your META tags on to a drupal page

Most blogging systems OR CMSes don't have the option to add the META KEYWORDS and META DESCRIPTION tags which are the key to search engine success to some extent.

Yes, I know you can add them in theme files... but if you change theme ? You have to re-add them. So we need a persistent solution which doesn't change while changing themes.

Below is a simple procedure where you can add your META tags to a drupal (taking 5.x here) system (without editing any of the theme files!).

Open common.inc in your favourite editor. common.inc is found in <drupal-install-path>/includes

Scroll down to Line Number 116 (or search for drupal_get_html_head).

After the first function line, you will see a line like this -

 
$output = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";

You then append these lines RIGHT AFTER the above line (else its not going to work).


$output .= '<meta name="keywords" content="keywrd1,keywrd2,..." />'."\n";

$output .= '<meta name="description" content="A small description here" />'."\n";

Save the file. Make a backup of the older file and place this new common.inc overriding the old one.

The above method has been tested and was found to work. So, if you have any problems just comment down here!

Have a nice day!

PHP: Receiving Function Arguments without declaring any parameters in prototype!

As you know, we usually declare functions in PHP like this -

function foo($arg1, $arg2) { 

// code

}

This leads to PHP-error when one of the argument is missing. To deal with this, we have an alternate method. We shall NOT declare ANY arguments in the prototype. Then we'll use func_get_args() to get all the arguments passed to function in an array. Further we can manipulate the array as we want.

function foo() {

$args = func_get_args();

}

When you will call foo(1,2,3) then $args[0] = 1 ; $args[1] = 2 and so on.

This way you can prevent PHP-Errors and have custom errors.

To handler PHP-Errors I suppose there does exist an function to set a custom handler for PHP-Errors. This is just an alternate method Wink

Syndicate content