Dec 7, 2011

Is Drupal 7 slow?

There are some performance issues with Drupal 7 currently on some server/server configurations.

As a start, you could try the 7.x-dev snapshot to see if there are any improvements.

  • Is your server is a shared hosting or your own server or local development environment?
  • Did you already use Drupal 6 in the same environment?
  • Did you enable the basic performance settings, like aggregating CSS/JS?
  • To do anything more, you will actually need to figure out what exactly is slow, there is often a specific bottleneck that is slowing down the whole site. As a start, you could enable devel.module and the query logging to see if there are any slow queries on that page.
  • If this is your own server, I strongly suggest to install and enable APC.

Most probably, you are hitting Avoid re-scanning module directory when multiple modules are missing. It happens if you have some missing modules in your installation.

Try to check your system table:

[php]SELECT name, filename FROM system WHERE type = 'module' AND status = 1 ORDER BY filename[/php]

And clean-up any modules that are still enabled but missing from the filesystem.

Overall, Drupal 7 is way more resource friendly and scalable then Drupal 6, other then some unfortunate regressions like this one.

Drupal 7 is optimized out of the box for large website featuring advanced cache features, reverse proxy, load balancer. You would say that this would make drupal 6 too fly, but there is noticable difference between drupal 6 and drupal 7 performace with same high end server setup.

Drupal 7 may let you down initially, but given the proper hardware and software environment, you can do wonders with drupal in terms of speed.

Drupal 7 uses too many files and like D6, it uses also too many SQL queries (in comparison with other CMS). So the first hit could take time, especially when you have a slow disk and files are not in OS cache.

In a normal situation, when cache is available, everything should be ok. There are many layer of cache: OS cache to avoid reading PHP files, opcode cache (like APC, not enabled by default) to avoid re-parsing PHP files, MySQL cache to avoid re-execute queries multiple times.

Morally, most of the time its not drupal, its probably the server at fault. Its true over the time drupal has evolved to be a resource hungry. But its only till you precise it that way. The fact is that drupal 7 is infact very resource friendly, since when it is used on a VPS with MemCache, APC installed then it flew like anything.

Learn PHP | PHP Tutorials | PHP Lessons | Part 2

So welcome back to part 2 of the PHP tutorial. If you are new to PHP then I would recommend you to first check the Part 1


Variables




  • Within this lesson you will learn how to assign values to variables in PHP and use them in some expression.

  • The topics covered are :



  1. Understanding Variables.

  2. Data Types.


Let’s get started right away…..


Understanding Variables




  • Variables

    • Variables are containers in which values can be stored and later retrieved.

    • They are basically the building blocks of any programming language.




For eg :- you can have a variable called “$number” that holds the value the value  “5



[php]$number = 5;[/php]

OR


$name that holds the value “bruce



[php]$name = "bruce";[/php]

Note :-        In PHP a variable will always be prefixed with a “$” symbol. If you can remember that declaring variable will be SUPER-EASY….




  • Just take “=” symbol with variable name on the left and value you want on right.


Here take a look at the example : -



[php]$name = "bruce";
echo "Hello";
echo $name;[/php]

 









Output produced is : Hello bruce.


  • Above example uses the “echo” command to display the value stored in a variable, in the same way that you would display a fixed piece of text.



  • The more descriptive your variable names are the more easily you will remember what they are used for, when you come back to a script several months later.



  •  Good variable name tells exactly what kind of value you can expect to find and stored in them.

  • Also, Variable name can only contain letters, numbers and underscore character. And each must begin with a letter or a underscore.

  • When the variable is assigned, the value given doesn’t have to be a fixed value


For eg :-



[php]$sum = 16 + 30;[/php]

-      ’16 + 30’ can also be an expression. An expression is where two or more values are combined using an operator to produce a result.


Let’s take a look at this …..



[php]$sum = 16 + 30;
echo $sum;[/php]

-      As seen above the values ‘16’ and ‘30’ are combined using the ‘+’ symbol & result is returned using “echo” command.




  •  Text Strings

    • Text Strings always have to be enclosed in quotation mark(“”) mark, and most of the time it doesn’t make any difference whether you use single(‘’) or double(“”) quotes.

    • But when you are dealing with variables it does make a difference.




Let’s look at an example to be clearer on this.



[php]$name = "bruce";
echo "Hello, $name";[/php]

  • Here the value of the variable is included in the string.








Output produced is : Hello, bruce.

Now look at this example below.



[php]$name = 'bruce';
echo 'Hello, $name';[/php]

  • Here no substitution of any variable takes place and output thrown is








Output produced is : Hello, $name.


  • You can overcome this by using ( ) OR { }



  • So if you want to display weight value with a suffix, your statement might look like this


[php]echo "The total weight is { $weight } lb";[/php]

  • If the braces hadn’t being placed around this particular weight variable , PHP would find a value which doesn’t exist. Like this


[php]echo  "The total weight is $weight lb";[/php]

  • Not to be too confusing but you can also do the same thing by using concatenation operator “.” to join two or more strings together as shown here


[php]echo 'The total weight is ' . $weight . 'lb' ;[/php]

-      The three values here are two fixed string and a variable.


-      If you assign a value to variable i.e $weight = 99 . The statement would produce output like this.









Output produced is : The total weight is 99lb.

Data Types




  • Each variable that holds certain value has a data type that defines what kind of a value it is holding.


























Data-type



Description


BooleanA truth value can be TRUE or FALSE
IntegerA number value, can be a positive / negative whole number
Double (or float)A floating point value can be any decimal number
StringAny alphanumeric value, any ASCII character.


  • When you assign a value to a variable the data type is also set.

  • PHP determine the data type automatically, based on value you assign to the variable.

  • If you need to check what data-type PHP thinks the value is you can use the gettype() function.


[php]$value = 7.2 ;
echo gettype($value);[/php]

  • Running this function, the data-type of a decimal number is double.

  • The complimentary function of gettype() is settype(), which lets you overwrite the data-type of a variable.


For eg:-



[php]$value = "22 January 2010";
settype( $value, "integer");
echo $value;[/php]

  • In this case the string begins with number, but the whole string is not an integer. The conversion converts the first non-numeric character and discards the rest and the output produced is just the number 22.


 









Output produced is : 22


  • Sometimes PHP will perform an implicit data-type conversion if values are expected to be of a particular type which is known as Type Juggling.


     For eg:-



[php]echo 100 + "10 inches" ;[/php]

-      The addition (+) operator expects to sit between two numbers. String type values are converted to double or integer in this case “10 inches” is treated is “10” before the addition operation is performed so the result is “110









Output produced is : 110


  • The same thing happens when a string operator is used on numeric data.

  • If you perform a string operation on numeric data-type, the numeric value is converted to a string first. We saw this earlier when we used the concatenation “.” operator to display a numeric value.

  • It is possible to use the value stored in a variable as the name of another variable.


-      Again, I know this might sound a bit confusing so let’s look at an example.



[php]$my_age = 21 ;
$varname = "my_age";
echo "the value of $varname is ${ $varname }";[/php]

-      The output produced in this example is









Output produced is : The value of my_age is 21

-      Because the string “my_age” is enclosed in a double quotes the dollar($) sign indicated that a variables value should become a part of string.


-      The construct shown i.e $ { $ varname } indicates that the value of variable should become a part of the string which is known as Variable Variables.


-      The braces around the variable $ { $ varname } is to indicate that it should be referenced first.


-      The next example shows the same output as the last one except that it uses the concatenation operator.



[php]echo 'The value of ’ . $varname . 'is' . $$varname;[/php]






Output produced is : The value of my_age is 21

So here we end our part 2 and I recommend you to go through the entire tutorial once again, and replicate all the examples in your localhost and test it if you are prepared for the 3 part.

download

Dec 4, 2011

Simple JQuery Toggle Tutorial | CSS JQuery Slide Toggle

Today I am going to share a very common and easy jquery tutorial with you. A JQuery Slide Toggle function.

.slideToggle() function is used to hide or show matched elements in a sliding effect.

So the basic syntax is

[js]$("div").slideToggle("slow");[/js]

So this was the basic syntax on how to slide toggle a div, now lets start with some real working examples.

So first the basic html code:



[html]
<div id="toggle">
<ul>
<li>Youtube Video Scraping</li>
<div>
Always I wondered to display youtube videos below my posts or for some other purpose. But always had to use some plugins or some complicated scripts. So finally coded for you people a small function which will fetch or scrape...<a href="http://webstutorial.com/youtube-video-scraping-fetch-youtube-video-through-rss/programming/php">Continue reading</a>
</div>
<li>WordPress Multiple Category Search</li>
<div>
Since when I started wordpress, I had a question in my mind, why wordpress doesn’t give multiple search option? I googled a lot, but couldn’t find a plugin or code which exactly works. So finally decided to go more into...<a href="http://webstutorial.com/wordpress-multiple-category-search/content-management-system-cms/wordpress-cms">Continue reading</a>
</div>

<li>Youtube Video Scraping</li>
<div>
Always I wondered to display youtube videos below my posts or for some other purpose. But always had to use some plugins or some complicated scripts. So finally coded for you people a small function which will fetch or scrape...<a href="http://webstutorial.com/youtube-video-scraping-fetch-youtube-video-through-rss/programming/php">Continue reading</a>
</div>

<li>Ten WordPress Useful Functions And Snippets</li>
<div>
Some useful WordPress PHP funtions. Just copy and paste these functions in your themes functions.php file Change the WP Login Logo & URL Link Load JQuery From Google CDN How to remove the WordPress Version Information Remove Default WordPress Meta...<a href="http://webstutorial.com/ten-wordpress-useful-functions/content-management-system-cms/wordpress-cms">Continue reading</a>
</div>

<li>A Good PHP Developer Can Answer This | PHP Test</li>
<div>
PHP developers go through 3 stages in their life Beginner Good Best A beginner PHP coder is some one who just started making some PHP projects in CMS like WordPress, Joomla, Magento and other PHP based CMS. A good PHP... <a href="http://webstutorial.com/good-php-developer-answer-php-test/programming/php">Continue reading</a>
</div>

</ul>
</div>
[/html]


And finally our js


[js]
<script type="text/javascript">
$(document).ready(function() {
$("li").click(function(){
$(this).toggleClass("active");
$(this).next("div").stop('true','true').slideToggle("slow");
});
});
</script>
[/js]

Explanation:

In our basic html layout, we have placed a div exactly next to our li. So we tell the jquery to slide exactly the next div of the current clicked li. If we directly write slideToggle then it will slide all the div's of the current page. In the above js code, we are also using a stop() function. This is essential to use, to avoid multiple clicks on a same li making it to slide for continuous multiple times of sliding.

Here's a working demo of the above code