SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast NuttySkunk's Avatar
    Join Date
    Jan 2012
    Location
    United Kingdom
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Small PHP script causing memory issues - makes no sence!!!

    I have a script that checks the status of a persons Skype account (online, offline etc), for some reason it has caused resource issues (memory), or atleast it seems to be at fault.

    Here is the script:

    PHP Code:
    <?php
    $data 
    file_get_contents('http://mystatus.skype.com/' $username '.xml');
    preg_match('@<presence xml:lang="NUM">(.*?)</presence>@i'$data$match); 
    $status = ($match['0'] == '<presence xml:lang="NUM">2</presence>') ? 'online':'offline';
                    
    if(
    $status == 'online'){
         echo 
    'skype:' $username '?call">'
    }else{
         echo 
    'skype:' $username '?chat">';     
    }
    ?>
    I have removed some information from the script (just html), can anyone see an issue here? Does file_get_contents have issues with memory? It is only fetching a small XML file, the XML file definitely exists.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Only fetching a small XML file over a network, thats no smal feat. Just putting that out there.

    Are you certain this snipplet of code is the cause?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    Non-Member algozone's Avatar
    Join Date
    Jul 2006
    Location
    Hackensack, NJ
    Posts
    119
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are you sure you get fast response from skype server?

  4. #4
    SitePoint Enthusiast NuttySkunk's Avatar
    Join Date
    Jan 2012
    Location
    United Kingdom
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It certainly seems to be the cause but if I was absolutely certain I guess I would also know how to fix it lol.

    The website is just a simple HTML/CSS site with some elements of PHP but no database connections. This script is the only actual processing that PHP does on the pages (every page).

    I cannot be 100% sure that Skype is responding well but even if it is slow, would it cause memory issues on the server and not just a slow page load?

  5. #5
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Unless this is critical to the application, I'd move this to an AJAX call and let the client deal with it. If it is critical, create a cron job to cycle through the users which you intend to target and save the response locally. Additionally, be sure to add a timeout factor to all these requests and handle the timeout appropriately.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  6. #6
    SitePoint Enthusiast NuttySkunk's Avatar
    Join Date
    Jan 2012
    Location
    United Kingdom
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    Unless this is critical to the application, I'd move this to an AJAX call and let the client deal with it. If it is critical, create a cron job to cycle through the users which you intend to target and save the response locally. Additionally, be sure to add a timeout factor to all these requests and handle the timeout appropriately.
    It is not critical and the fall-back is designed to always allow the user to initiate a chat (the script is only to allow the button to initiate a call request if the Skype is online rather than a chat/message).

    Using AJAX is a good idea. I was thinking of running the script once when the use enters the site and caching that value and once the user has been on the site for 5mins it re-checks. Maybe I should combine the two.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •