Saturday 12th July 2008

by Sajith M.R

Blunder I ever made

I was writing a php code to parse images from a particular url . At the begining I used http://www.google.com as a testing url.

When I tested the php code from my local machine (http://localhost) it took time to get data from a remote url (google.com) . So I decided to check this code with my locally testing web page. So i write the code as bellow :

file: index.php

<?php

$content = file_get_contents(“http://localhost/”);

// parse($content);

?>

This is the biggest mistake I made that day. Did you find the mistake ?? Else try this code with your local machine. You can see your big blunder . Not only you, your system also will get hang .. :)

Because this is the longest recursive call you can call with your web server !!!

Regards

Sajith

Tags: , , , , , ,

· · · ◊ ◊ ◊ · · ·

6 Responses to “The biggest blunder I ever made with PHP”

  1. Asti says:

    I don’t know how i came across this page, but its not as much of a blunder as your understanding of basic programming paradigms.

    There are synchronous calls and asynchronous calls.
    file_get_contents is a synchronous call, while a RESTful request, like http://localhost/ is an asynchronous one.

    Getting http://localhost/ requires that the synchronous call be completed, but since it won’t be completed nothing will happen. The server will simply wait it out. What does recursion even have to do with this?

    Even, won’t do a thing. Don’t confuse the n00bs. :P

  2. Sajith M.R says:

    Hello Binny, Check now… There was some error

  3. Binny V A says:

    I cannot see any code – all I see is…

    file: index.php >>

    215185bfd4f7d85644ac3f87b850f03a000

  4. TheAnand says:

    Oh, I think that explains why my hosts analytics like webalizer and webstats are showing a higher count than that of analytics. Am I right in taking this as the reason for the problem?

  5. Sajith M.R says:

    Hey anand,
    Calling an url from file_get_contents never affect your adsense and analytics. Because they are javascript. This call never execute those scripts. Only browsers visit can be counted using your analytics etc stuffs

    Regards
    Sajith. M.R

  6. TheAnand says:

    Hehe….I really thank you for not using my blog as a test url….which would had got me a ton of hits and impressions on adsense!!!!! That is a really expensive mistake in php

· · · ◊ ◊ ◊ · · ·

Leave a Reply

وظائف 2011 تحويل العملات برامج برنامج تسريع التحميل برنامج الفلاش برنامج محول الصوتيات عربي hotel 2011 زيادة رواتب العساكر 1431