SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 52
  1. #26
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    930
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    cpradio, how is that supposed to work (solution #2):
    PHP Code:
    if ($json_array[0]->name == "live_user_{$channelName}"
    how do you expect $json_array[0] to be an object? The working code in the first post clearly indicates this is array not object. I doubt this will work.

  2. #27
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Lemon Juice View Post
    cpradio, how is that supposed to work (solution #2):
    PHP Code:
    if ($json_array[0]->name == "live_user_{$channelName}"
    how do you expect $json_array[0] to be an object? The working code in the first post clearly indicates this is array not object. I doubt this will work.
    It does work, because the json_decode is not forcing it to be an associative array, so php decodes it to an object, you can see the manual on json_decode to see that not passing "true" as the second parameter makes it an object.

  3. #28
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Lemon Juice View Post
    Good catch! I made a typo in my code and even if I looked at it several times now I couldn't make out what could be wrong... The first element was empty array, which tripped up the code that followed. BTW, that's why I strongly believe that E_NOTICE error reporting should be always enabled when developing any code - if it was enabled then php would immediately throw a notice error about uninitialised variable in that line and all would be clear
    I have E_NOTICE error reporting on and I still didn't get any useful notice, just kept getting "Cannot use string offset as an array in /home/sglivest/public_html/livestreams2.php on line 16".

    Very odd, as I get notices on the other uninitialized variables.

  4. #29
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    930
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    It does work, because the json_decode is not forcing it to be an associative array, so php decodes it to an object, you can see the manual on json_decode to see that not passing "true" as the second parameter makes it an object.
    Interesting, I've never used those additional json options so I wasn't aware of them!

    Quote Originally Posted by cpradio View Post
    I have E_NOTICE error reporting on and I still didn't get any useful notice, just kept getting "Cannot use string offset as an array in /home/sglivest/public_html/livestreams2.php on line 16".

    Very odd, as I get notices on the other uninitialized variables.
    It's odd and it turns out that php is not reporting E_NOTICE for $arr[] = value; if $arr is not initialised. It's even documented:
    Code:
    $arr[key] = value;
    $arr[] = value;
    // key may be an integer or string
    // value may be any value of any type
    If $arr doesn't exist yet, it will be created, so this is also an alternative way to create an array. This practice is however discouraged because if $arr already contains some value (e.g. string from request variable) then this value will stay in the place and [] may actually stand for string access operator. It is always better to initialize variable by a direct assignment.
    To me it's a bit inconsistent, I don't know why arrays are an exception to the rule but this is php after all

  5. #30
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Lemon Juice View Post
    Interesting, I've never used those additional json options so I wasn't aware of them!
    Yeah, its a great way to keep an OOP feel to your code if that is your preference

    Quote Originally Posted by Lemon Juice View Post
    It's odd and it turns out that php is not reporting E_NOTICE for $arr[] = value; if $arr is not initialised. It's even documented:

    Code:
    $arr[key] = value;
    $arr[] = value;
    // key may be an integer or string
    // value may be any value of any type
    If $arr doesn't exist yet, it will be created, so this is also an alternative way to create an array. This practice is however discouraged because if $arr already contains some value (e.g. string from request variable) then this value will stay in the place and [] may actually stand for string access operator. It is always better to initialize variable by a direct assignment.
    To me it's a bit inconsistent, I don't know why arrays are an exception to the rule but this is php after all
    Thanks for looking that up (I didn't get a chance to yet), definitely is inconsistent, but at least that explains why I didn't catch it right away.

  6. #31
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Okay, so we have made progress. I can now see the format of the page and there are no errors. And it does load very quickly. But how long does it take to show up with a name? I have been live on my stream for 5 minutes and my name has not shown up yet. I have my name added to the list too.

  7. #32
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Do you have a cronjob running the first file ever X minutes?

  8. #33
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No, how would the command be written for this cron job?

  9. #34
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Nvm, you just put the filename right? Which file are we running though, the one thats seeing if its live or the one thats projecting the live users.

  10. #35
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    You will need to put more than just the file name, something like php5 /path/to/filename.php

    And you want the one that is seeing if its live. The one that projects the live users is to be used on your page.

  11. #36
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I put php5 /home/sglivest/public_html/livestreams.php as the cron job set at every 3 minutes.

    I have left my stream live for an hour and its still not showing up. AHHHHH!!!! This is frustrating lol. I guess on the bright side theres no errors.

  12. #37
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Do you have SSH access? As you may need to run that command to verify it is correct. Sometimes you have to point to the location of the php5 executable, such as, /usr/bin/php5. I'd also recommend asking your host where the php/php5 executable is located so you can easily run it.

  13. #38
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes I do, although im not quite sure how to use it.

    The file is not being ran in the cron job though so obviously im not tryping it in correctly yet. Im very, very sorry for being such a pest.

  14. #39
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Okay, if you have SSH access, you need to download PuTTY

    You will type in your domain name, use Port 22, and press Open
    You will enter your username and password
    Once logged in, type "whereis php5", if it returns blank, then use "whereis php"

    You are looking for a line similar to
    Code:
    php5: /usr/bin/php5 /etc/php5 /usr/lib/php5 ...
    Or (if your whereis php returned a path)
    Code:
    php: /usr/bin/php /etc/php /usr/lib/php ...
    The important piece is the one that contains /bin/

    You will put the one that contains /bin/ in your cronjob, like so
    Code:
    /usr/bin/php5 /path/to/php/file.php
    Or (if your whereis php returned a path)
    Code:
    /usr/bin/php /path/to/php/file.php

  15. #40
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Okay, so now I can see 2 users on the list. But those users arent even online, and I haven't seen my name (which I have been live for 10 minutes now). And I have my cron job set for 2 minutes.

  16. #41
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,902
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Reply to Post #15

    Wouldent your first suggestion do the same thing my code is doing now just within a div? I need the entire process to be sped up somehow.

    I cant necessarily guess if they are online or offline. The list has to be comprised of only live users that are streaming. When a visitor comes to my website then they will be able to click the live stream link bringing them to a page to watch their stream.
    Hi sgsecret;

    I checked and found that using position:relative and position:absolute works fine using html script with images but fails miserably when including PHP script

    So I have been busy looking for a solution and think that PHP Curl with Multilpe Threads maybe the answer to...

    http://php.net/manual/en/function.curl-multi-init.php

    Check out the demo using your data (source link included at the bottom of the page):
    http://johns-jokes.com/downloads/sp-a/curl-multi-exec/
    The code does not work exactly just returns the source greater than about 5 bytes.
    I think it is a good base and does not require a lot of work to complete.

    Upon reflection that the guy that wrote the API would have expected a search for users of a particular game and supplied a link including the game that returns all the players online. Maybe worth checking?

    Quote Originally Posted by sgsecret View Post
    Okay, so now I can see 2 users on the list. But those users arent even online, and I haven't seen my name (which I have been live for 10 minutes now). And I have my cron job set for 2 minutes.
    Last edited by John_Betong; Oct 7, 2012 at 11:58. Reason: spelling: not my fortay
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  17. #42
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I cant view the source, 400 error.

  18. #43
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,902
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by sgsecret View Post
    I cant view the source, 400 error.
    Whoops, sorry about that - try it now.

    Provlem due to: The link used to work when I was testing on a subdomain and used /index.php/src=true. When I moved the source to the downloads folder I forgot to make the link relative.

    If it still does not work after refreshing the page then try this link:

    http://johns-jokes.com/downloads/sp-...hp?source=true
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  19. #44
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,902
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    @sgsecret ;

    I cant view the source, 400 error.
    Here we go:
    PHP Code:
    <?php /* */ ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"  lang="en" xml:lang="en">
    <head>
    <?php include '_head.php';?>
    </head>
    <body>
      <hr />  
        <h1>
          <a href='http://www.sitepoint.com/forums/showthread.php?890672-Help-with-speeding-up-php-code&p=5201789#post5201789'>
            SitePoint Forum:
          </a>
        </h1>
      <hr />  

      <div id='main'>
        <?php
          
    echo "<h2 class='flr'>start: " .date('H:i:s') ,'</h2>';
          
    $nodes = array
          (
              
    "meditor996""malidude""tacsecret""izual155""porkyhd"
              
    "tachydro#""church_""tainttubes""kurimlinn""TacvFOX",
              
    "tacpinkiepie""dkrstarcraft""chaosstarcraft""thepandrexlive",
              
    "zren89""1soulfire""sallvain""sg_goldster""adramelechii"
              
    "dragon""dignitasselect""sing_sing""desrowfighting""eghuk",
              
    "eg_idra""rootcatz""liquidsheth""spanishiwa""mtwdimaga",
              
    "whitera""meditor996""colqxc""kraglord""tsm_dyrus""nyjacky",
              
    "crs_saintvicious""tsm_theoddone""mstephano""protech""tacmoose"
          
    );
          
    $node_count count($nodes);

          
    $curl_arr = array();
          
    $master   curl_multi_init();

          
    // initialise each and every node
          
    $uuu =  "http://api.justin.tv/api/stream/list.json?channel=";
          for(
    $i2 0$i2 $node_count$i2++)
          {
            
    # echo '<br />',  
            
    $url $uuu ."{" .$nodes[$i2] ."}";
            
    $curl_arr[$i2] = curl_init($url);
            
    curl_setopt($curl_arr[$i2], CURLOPT_RETURNTRANSFERtrue);
            
    curl_multi_add_handle($master$curl_arr[$i2]);
          }

          
    // Curl_Multi_exec - go and do your stuff
          
    do
          {
            
    curl_multi_exec($master,$running);
          } while(
    $running 0);

          
    // 
          
    echo '<dl>';
            for(
    $i2 0$i2 $node_count$i2++)
            {
              
    $results curl_multi_getcontent  $curl_arr[$i2]  );
              
    $len strlen$results );

              if(
    $len 2)
              {
                 echo 
    '<dt>'
                   
    fn_json_decode($results$nodes[$i2] );       
                 echo 
    '</dt>'
                 echo 
    '<dd>'
                   echo 
    htmlspecialchars($results);       
                 echo 
    '</dd>'
              }
            }
          echo 
    '</dl>';
          echo 
    "<h3 class='flr'>finish: " .date('H:i:s') .'</h3>';


      
    //===============================
      
    function fn_json_decode$results$NAME)
      {
          
    $json_file  =  $results#@file_get_contents($FFF, 0, null, null); 
          
    $json_array json_decode($json_filetrue); 
          if ( isset(
    $json_array[0]['name']) && $json_array[0]['name'] == "live_user_{$NAME}"
            
    $live true
          else 
            
    $live false

          
    # Prevent warnings and errors - Not known
          
    $viewers      ' $viewers ';
          
    $channelTitle ' $channelTitle ';
          
    $gameSTR      ' $gameSTR ';
          
    $i            =  999;   
          
    $url          "http://www.twitch.tv/$i";  
          
          echo 
    "<a 
                  href='" 
    .$url ."' 
                  target='_blank' 
                  title='" 
    .$channelTitle ."' 
                  style='color:#00f' 
                >"
                  
    .$NAME
               
    .'</a>'

          
    #echo "<font style=tahoma color=white size=2>" ."<br>" ."&nbsp;&nbsp; &nbsp;"
          #     .   $viewers . " " . $gameSTR . " " . $userLINK . $i . "</a>" 
          #     ."</font>"; 
      
    }
      
    ?>  
      </div>
      
      <div id='src'>
        <a href='index.php?source=true'>
          Source
        </a> 
        <br /> 
        <?php
          
    if(isset( $_GET['source']))
          {
            
    highlight_file__FILE__);
          }
        
    ?>

      </div>  

    </body>
    </html>
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  20. #45
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    For some reason my provider has disabled line 46 "curl_multi_exec($master,$running);" for security reasons. =(

  21. #46
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sgsecret View Post
    Okay, so now I can see 2 users on the list. But those users arent even online, and I haven't seen my name (which I have been live for 10 minutes now). And I have my cron job set for 2 minutes.
    Okay, now login via FTP or SSH and check the timestamp of your channels.txt file to verify it is indeed being updated every two minutes, like you asked it to be. Once that is verified, let me know. As logically that should be the only reason why you are not seeing it updated.

  22. #47
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ur right. I have confirmed that it is actually not executing the cron job. "php5 /home/sglivest/public_html/livestreams.php" does not work. I will continue to try some different variations.

  23. #48
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    I worked with @sgsecret ; via PM as we needed to exchange confidential information, but now his cronjob is running smoothly using the command php ~/public_html/sglivest/Livestreams.php

    Just wanted to give everyone an update.

  24. #49
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    46
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes. It is working properly. And I just wanted to thank everyone who helped me out here. I know I was a pain in the ass but I am a very happy man now that everything works.

    If you are interested heres my main website where my new live stream list is broadcasted
    http://www.sentinelgaming.net - Its on the right hand side of the home page.

    THANKS!

  25. #50
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,902
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by sgsecret View Post
    Yes. It is working properly. And I just wanted to thank everyone who helped me out here. I know I was a pain in the ass but I am a very happy man now that everything works.

    If you are interested heres my main website where my new live stream list is broadcasted
    http://www.sentinelgaming.net - Its on the right hand side of the home page.

    THANKS!
    I am pleased that you managed to sort your problem and while looking for a solution I learnt a lot about Curl which I am sure will be useful for a future project.

    I am curious to know why the script I supplied is timing out. This is unfortunate because it is appears to be a very fast solution.

    http://www.johns-jokes.com/downloads...exec/index.php
    PHP Code:

    {"url":"/api/stream/list.json?channel={meditor996}","error":"rate limit exceeded for 173.199.151.52"
    Nice site by the way, quite colourful
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014


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
  •