The biggest blunder I ever made with PHP

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

6 Comments , , , , , ,

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

  1. TheAnand July 12, 2008 at 2:57 pm #

    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

  2. Sajith M.R July 12, 2008 at 4:01 pm #

    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

  3. TheAnand July 12, 2008 at 4:04 pm #

    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?

  4. Binny V A July 12, 2008 at 9:27 pm #

    I cannot see any code – all I see is…

    file: index.php >>

    215185bfd4f7d85644ac3f87b850f03a000

  5. Sajith M.R July 14, 2008 at 3:01 pm #

    Hello Binny, Check now… There was some error

  6. Asti August 27, 2009 at 1:16 am #

    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

Leave a Reply

More in php (57 of 104 articles)


If you wanna know , what is others review or opinion about your website, You can use this wordpress ...