1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Creating a Real Time Application in PHP

Discussion in 'Web Design & Development' started by JiminSA, May 9, 2015.

Thread Status:
Not open for further replies.
Advertisement
  1. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    3,388
    First Name:
    Jim
    I am currently working on a php based Live Auction site and would like opinions on the best approach to use for seamless simultaneous interaction with unlimited users.
    I have looked at Websockets and Ratchet, but would love to hear your advice ...:)
     
  2. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    3,388
    First Name:
    Jim
    Well I've found an alternative solution and would be pleased to hear some constructive criticism about my methodology ...
    I am using this magical bit of Javascript to refresh a marquee and a bidding button to simulate streaming ...
    Code:
    	<script>
    	var refreshId = setInterval(function()
    	{
    		 $('#marquee').fadeOut("slow").load('marquee.php').fadeIn("fast");
    	}, 5000);
    	</script>
    	
    	<script>
    	var refreshId = setInterval(function()
    	{
    		 $('#bid_button').fadeOut("slow").load('button.php').fadeIn("fast");
    	}, 5000);
    	</script>
    
    and I utilise $_SESSION variables within the refreshed divs (content held in the "called" php pages) to update marquee and bid button content to reflect the current bid and bidder and the next bid respectively.
    The code rolls like this ...
    Live Auction page
    HTML:
    						<div id="marquee" name="marquee" class="span3">
    							<br /><img src="images/loading.gif" alt="loader">
    <!-- Rendered by the Javascript (up top) - the 1st "var refreshId" -->
    						
    						</div>
    						<form name="tender" id="tender" action="process1.php" method="post">  
    							<input type="hidden" name="bidder" value="<?php echo $_SESSION['memno']; ?>">
    							<input type="hidden" name="bidamount" value="<?php echo $_SESSION['next_bid']; ?>">
    						<!-- The Bid Submit button -->
    							<div id="bid_button">
    <!-- Rendered by the Javascript (up top) - the 2nd "var refreshId" -->
    							</div>
    						</form>
    
    marquee.php
    PHP:
    <?php

        session_start
    ();

        
    date_default_timezone_set('Africa/Johannesburg');
        
        include (
    'functions.php');
        
        
    OpenDatabase();

        
    GetBid();
        
    $temp_row mysql_fetch_array($temp_result);
        
    $_SESSION['bidder'] = $temp_row['bidder'];
        
    $_SESSION['curr_bid'] = $temp_row['latest'];

        
    $nb_num trim($_SESSION['curr_bid'], "R");
        
    $nb_num $nb_num $_SESSION['factor'];
        
    $_SESSION['next_bid'] = "R" $nb_num;

    ?>
                                <h1><marquee behavior="scroll" direction="left" scrolldelay="90" SCROLLAMOUNT=15>Current Bid <i class="red"><?php echo $_SESSION['curr_bid']; ?></i> from <?php echo $_SESSION['bidder']; ?> ...</marquee></h1>
    button.php
    PHP:
    <?php

        session_start
    ();

        
    date_default_timezone_set('Africa/Johannesburg');

        include (
    'functions.php');
        
        
    OpenDatabase();

        
    GetBid();
        
        
    $temp_row mysql_fetch_array($temp_result);

        
    $_SESSION['curr_bid'] = $temp_row['latest'];

        
    $nb_num trim($_SESSION['curr_bid'], "R");
        
    $nb_num $nb_num $_SESSION['factor'];

        
    $_SESSION['next_bid'] = "R" $nb_num;
    ?>
                                    <input class="btn btn-green button" style="margin-top:20px;" type="submit" id="bid" name="submit" title="Click to bid on the lot" value="Your Next Bid <?php echo $_SESSION['next_bid']; ?>?"</input>
     
  3. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    3,388
    First Name:
    Jim
    Woops! forgot to mention that I put the $_SESSION variables in a db to spread across logged in users ...
     
  4. Ent

    Ent Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,467
    First Name:
    Josiah
    That feels like the wrong way to do it, though I don't know what I'd suggest instead.

    The first problem, which I suppose is efficiency rather than anything else, is that every time you check you load the whole page. It would be better to first find out whether anything has changed before you go through the rigmarole of replacing the page.

    The other thing is that it's inherently a polling system, which means as well as constantly checking when nothing has changed, you don't find out immediately once something does.
    I don't know whether any of the current approaches to a push notifications system work terribly well, but if any of them is available they'd be preferable. (I guess you could fall back to a polling system for unsupported clients.)
     
  5. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    3,388
    First Name:
    Jim
    Not quite so Josiah, just 2 small divs are reloaded every 10 seconds not the whole page.
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Solved Creating Real
  1. Ricson
    Replies:
    2
    Views:
    612
  2. owlhootx
    Replies:
    15
    Views:
    1,729
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1147957

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice