Embedd Javascript in AJAX Response

Hi everyone…

I came across a problem few days back, it was about calling or embedding javascript result/response in AJAX response. I was working on one of the feature of PHP based site http://www.PingMyCompany.com

I found that, javascript can’t be called in AJAX response, possible reason being, AJAX response is build on server side while javascript is simply client side (I may be wrong here, OR there can be some other reason for this as well).

So what to do, what if we have to embed the output of some external JS file in AJAX response as below???

/****AJAX response START****/

/**********Some Response*******************/
/********** Some Response ******************/
/**********Response from some JS file*********/
<script src=”http://www.crunchbase.com/cbw/company/zigron.js&#8221; type=”text/javascript”>
</script>
/**********Some Response*******************/
/********** Some Response ******************/

/****AJAX response END****/

Now the response from JS file will not get embedded with AJAX response. So what I did to solve this issue is that I got the output of JS file in a PHP variable using file_get_content function as follows.

$contents = file_get_contents (“http://www.crunchbase.com/cbw/company/zigron.js&#8221;);

Alternatively you can do the same using cURL but file_get_content is really smart solution (if the JS is file is not suspicious…).

Once done, you must know the format of contents being returned by the JS file. Now you can do simple string manipulation on the contents to mangle it according to the requirements and just echo it where you want to embed it in AJAX response. I have removed document.write from the start of the string and escaped few of whitespace characters and that’s it….

****AJAX response START****

/**********Some Response*******************/
/********** Some Response ******************/
/**********Response from some JS file*********/
$content = file_get_contents (“http://www.crunchbase.com/cbw/company/zigron.js&#8221;);
$content = substr($content,16);
$content = substr($content,0, strlen ($content)-2);
$content = str_replace(“\\n”,””,$content);
$content = str_replace(“\\t”,””,$content);
$content = str_replace(‘\\”‘,””,$content);
echo $content;
/**********Some Response*******************/
/********** Some Response ******************/

/****AJAX response END****/

You can see the working example by clicking here. Click on “CrunchBase Profile” tab button which show ajax response built using remote JS file.

Feel free to discuss..

Thanks.

Keep Smiling 🙂

Posted in PHP. Tags: , , . 5 Comments »

Introduction to SEO

Hi Everyone…

I have been recently involved in SEOing (programmatically) a web application (PingMyCompany) and this involvement pushed me to study basics of SEO. Its really a fascinating area for me as it involves dealing with worlds top search engines and making them to consider your site more than other :). So here today I am starting with very basic concepts of What, Why and How SEO works. Later on, I will cover more beginners to intermediate stuff related to it and here it goes…

What is SEO?

Search Engine Optimization (SEO) is a system of website promotion or website marketing aiming to help a website rank favorably on internet search engines under keywords or key-phrases that are most important to your website. It is also referred to as Search Engine Marketing, Search Engine Positioning or Search Engine Placement. No matter what or how they name it – the bottom line is that prospective customer should be able to find your website.

Why SEO?

We have more than 100 million websites and registered domains on the internet. With so much competition on the internet, it is tough to be noticeable. With over one billion people surfing the internet on a daily basis worldwide, the goal of each website is to develop a niche for itself in a market to generate revenue. To achieve this task, a website needs a good volume of traffic from which the company forms its customer base.

A study has shown that 90% of the internet users use three major search engines – Google, Yahoo and MSN. The structure of these search engines is designed in such a way that whenever a user types in the needed search subject, the search engines bring up a list of websites ranked according to their relevance to the searched term. As most of the searched engine users do not search more than 30 results so it is clear that traffic goes to the higher ranked websites. Therefore, for drawing traffic to your website, it has to have high search engine ranking. To achieve this, it has to be search engine optimized.

How SEO works?

SEO helps in maintaining the path for search engines in a way that they handle the limits of the bots (a bot is a software program that imitates the behavior of a human, as by querying search engines) with crawler-friendly structural design, in addition to addressing indexing filtering concerns. SEO helps in making the website available to web-searchers by classifying keywords, most used by the target audience and by a proper use of the keywords and phrases into the text. It also helps in analyzing visitor’s activity including human and bot on the website.

A search engine has a program that mechanically gets WebPages. Such programs include spiders, bots and web crawlers. A search engine sends a spider to crawl the servers on the World Wide Web to find the documents to index for their database. While Indexing, it sorts out documents according to the search engine’s rules, like to set aside duplicates and store those, which meets the search engine’s predefined quality standards.

Whenever a person types a phrase or keyword in the search box of a search engine, the engine compares the keyword with its valued sites in its index. The search engine then evaluates the most appropriate information, which matches the user’s preferences. It is also important to have the links redirecting to your own website referenced by search engines.

That’s all for today, In next post I will try to explain the basics of how to optimizing a webpage, Do’s and Dont’s of webpage optimization.


Keep smiling 🙂

AMD vs Intel

Hi Everybody…

I have been disparaged by most of my friends and colleagues after I bought a laptop with AMD Athlon 64×2 processor. According to them AMD processors are no where near the Intel processors when it come to performance and price. So in this post I will just present a small comparison of both these processors just to make my friends think little different.

I was aware that after the launch of Intel’s Core 2 Duo, AMD has been struggling but still I preferred to go with AMD. Reason being, firstly, I want to see how AMD work, secondly it’s cheap.

Today, Intel has the crown in terms of both power and efficiency. AMD recently cut the prices for its top end processor, the Athlon 64×2 5200+, by a dramatic 50 per cent, hence making it affordable for the average customer. The landmark had drawn hard talk’s interest and today the AMD Athlon 64×2 will be pitted against its closest rival (at least in terms of price), the Intel core 2 duo E6400.

It would be unfair to not to attribute AMD for its competitive offerings in the form of Athlon 64 and Athlon 64×2 that forced Intel to start building the Core 2 Duo processor series. It was AMD’s revolutionary efforts for 64 bit operating systems, lower power consumption and better support for the multi-core processors that ushered into a new era that was being resisted heavily by Intel. In fact it can be said safely that if it were not AMD, the market would still be sitting at peaked out and inefficient dual core systems, consuming enough power to light up a house.

To compare both of these processors lets have a look at their performance using renowned benchmarks. (I personally have not benchmarked these processors, just presenting a summary of few existing results on the web that I have researched).

1. Memory benchmark

The SiSoft 2007 memory benchmark is the predefined standard upon which CPUs are measured for theoretical speed increments. Memory performance details like how wide the pipeline of information is present in between the system and the CPU.

SiSoft's Memory Test

SiSoft

Flow of information depends upon the bandwidth, hence removing any potential bottlenecks for the processor to perform tasks. During the test, both processors were equipped with PC 5400 DDR-2 RAM from Kingston and then examined thoroughly with and intensive memory test.

Due to the presence of Hyper Transport memory controller, inside the CPU itself, the Athlon 64 X2 5200+ makes its mark in this synthetic test leaving the Core 2 Duo behind in a trail of dust.

It can be be proved mathematically as follows:

Intel’s FSB = 64bits X 800MHz/8 = 6,400Mb/s.
AMD’s HTT= 32bits X 1000MHz X 2 (double- pumped)/8 = 8,0000Mb/s.

2. CPU Benchmark

CPU Test

CPU Test

Using SiSoft’s CPU benchmark, both the processors where again pitted against each other in a theoretical setup, presented by the benchmark suite.

The Intel core 2 duo edge slightly ahead of the AMD athlon 64×2 in this test but does not prove anything conclusive regarding the efficiency of processing in either of the present platform.

3. Prey

Prey

Prey

It is in the gaming benchmarks that the Intel E5400 gets ahead in comparison to the Athlon 64×2 5200+ processor. The test bed system was GeForce 8800 GTX graphics card running with two gigabyte of DDR2 RAM. The default resolution of 1024*768 was used as the lower resolution give more headway for the CPU to perform and the graphical processing unit does not present any bottleneck for the frames per second to roll out. First in line is the OpenGL powered Prey, a game based on Doom 3 engine.

They prey results did not show any significant difference between the two processors, which indicates the relatively close performance between the two brands.

4. Far Cry

Far Cry

Far Cry

In order to see the difference of performance between the two processors better, Far Cry a relatively older title was used. Core 2 Duo processor stood heads and shoulders above the Athlon 64 X2 5200+. The Far Cry physics engine is extremely processor intensive, and the Athlon 64×2 5200+ is definitely lagging behind by a good 20 frames per second, which can prove to quite worrying if the physics are dumped heavily on this processor.

5. Conclusion

Given the two synthetic and two real world benchmarks, there is not a lot which goes against the Athlon 54 X2 5200+. The Intel offering is definitely superior, but given the relatively close prices of each, the performance differences are really marginal and in the end boils down to one’s own taste for either brand. If one is AMD fan, then the AMD Athlon 64×2 5200+ will more than fit the requirement for a performance processor in comparison to the Intel Core 2 Duo E6400 processor.

Few References:
1. http://www.itp.net/index.php?option=com_content&view=article&id=493585&Itemid=1
2. http://www.gamingparents.org/index.php?option=com_content&task=view&id=173&Itemid=64
3. http://en.wikipedia.org/wiki/Athlon
4. http://en.wikipedia.org/wiki/Core_2_duo

Keep Smiling 🙂