If you are looking for the epic motorcycle journey blog that I've written, please see the Miles By Motorcycle site I put together. 
  • Subscribe to this RSS Feed
  • New Flu Stain Discovered
    04/25/2009 2:17PM

    As reported on Slashdot:

    Combat Wombat writes with this excerpt from Reuters: "A strain of flu never seen before has killed up to 60 people in Mexico and also appeared in the United States, where eight people were infected but recovered, health officials said on Friday. Mexico's government said at least 20 people have died of the flu and it may also be responsible for 40 other deaths. [The government] shut down schools and canceled major public events in Mexico City to try to prevent more deaths in the sprawling, overcrowded capital. ... Close analysis showed the disease is a mixture of swine, human and avian viruses, according to the CDC. Humans can occasionally catch swine flu from pigs but rarely have they been known to pass it on to other people. Mexico reported 1,004 suspected cases of the new virus, including four possible cases in Mexicali on the border with California.

    See the slashdot article.

  • PHP Leaks Memory in socket_read()
    04/13/2009 1:51PM

    This has taken quite some time to track down. Ref this bug report over at bugs.php:

    http://bugs.php.net/bug.php?id=42846

    Personally from what I'm seeing, the comment in the report that this is just how PHP memory management works is incorrect. Calls to socket_read() in PHP 5.2.6 under Ubuntu 8.10 causes the process to grow without bounds.

    Here is a slightly modified sample client and server pulled from the PHP documentation socket examples page::

    The server code:

    <?php
    error_reporting(E_ALL);
    
    /* Allow the script to hang around waiting for connections. */
    set_time_limit(0);
    
    /* Turn on implicit output flushing so we see what we're getting
     * as it comes in. */
    ob_implicit_flush();
    
    $address = '127.0.0.1';
    $port = 10000;
    
    if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
        echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
    }
    
    if (socket_bind($sock, $address, $port) === false) {
        echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
    }
    
    if (socket_listen($sock, 5) === false) {
        echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
    }
    
    do {
        if (($msgsock = socket_accept($sock)) === false) {
            echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
            break;
        }
    
        do {
    
    	 	print( "MEMORY USAGE BEFORE READ IS '" . memory_get_usage() . "'\n" );
    
            if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
                echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
                break 2;
            }
    
      	 	print( "MEMORY USAGE AFTER READ IS '" . memory_get_usage() . "'\n" );
    
        } while (true);
    
        socket_close($msgsock);
    
    } while (true);
    
    socket_close($sock);
    
    ?>
    
    

    The client code:

    <?php
    error_reporting(E_ALL);
      echo "<h2>TCP/IP Connection</h2>\n";
      /* Get the port for the WWW service. */
    $service_port = 10000;
      /* Get the IP address for the target host. */
    $address = gethostbyname('localhost');
      /* Create a TCP/IP socket. */
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if ($socket === false) {
        echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
    } else {
        echo "OK.\n";
    }
      echo "Attempting to connect to '$address' on port '$service_port'...";
    $result = socket_connect($socket, $address, $service_port);
    if ($result === false) {
        echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
    } else {
        echo "OK.\n";
    }
      while( true )
        {
          echo "Sending Hello";
          $in = "hello\n";
          socket_write($socket, $in, strlen($in));
        echo "OK.\n";
          sleep( 1 );
        }
      echo "Closing socket...";
    socket_close($socket);
    echo "OK.\n\n";
    ?>

    Running it:

     Running it will produce a constantly growing server process.

     MEMORY USAGE BEFORE READ IS '61324'
    MEMORY USAGE AFTER READ IS '61728'
    MEMORY USAGE BEFORE READ IS '61788'
    MEMORY USAGE AFTER READ IS '61924'
    MEMORY USAGE BEFORE READ IS '61924'
    MEMORY USAGE AFTER READ IS '61956'
    MEMORY USAGE BEFORE READ IS '61956'
    MEMORY USAGE AFTER READ IS '61988'
    MEMORY USAGE BEFORE READ IS '61988'
    MEMORY USAGE AFTER READ IS '62020'

  • How To Opt Out Of Verizon Info Sharing
    03/09/2009 8:50AM
    If you don't want Verizon to start sharing various bits of your personal info with "affililiates, agents, or parent companies", you must notify them within 45 days. Further details can be had here.
  • Removing Extra Whitespace Between List Item Entries in IE
    03/06/2009 2:29PM
    647

    Using a CSS styled unordered list you can create a fairly sophisticated navigational bar with rollover states.

    In IE6 and IE7 without some special consideration, you end up with spurious white space rendered between the list item.

    Click here for and HTML example of the problem (you'll need to be using IE 6 or IE 7).

    Click here for an example of the fix
    and a detailed explanation of how to do it.

  • Finding Next and Prev entries from an SQL Result set given only a single reference number.
    03/02/2009 6:48PM

    For ages I've been doing handstands dealing with the next and previous problem in SQL result sets. This is used, for instance, in the Member Photos section. 

    Today I've been working to try to improve linking to the shared photos area. As of this writing, I still use the long encrypted links which embed values that make it easier for me to generate the next and previous link.

    For ages, I've had this sense that there had to be an easier way.

    And of course there is a MUCH better way than I've been doing it. Once I saw the solution, I found myself thinking "now why didn't I think that of that, it's so obvious".

    So let's say you have a photo_id value which is the unique key of your list of photos. You want to know what the photo_id of the next and previous photos in the list is.

    You can solve this problem with a very simple LEFT JOIN:

    SELECT photos.photo_id, next.photo_id AS next_id, prev.photo_id AS prev_id
    FROM photos
    LEFT JOIN photos AS next ON next.photo_id > photos.photo_id
    LEFT JOIN photos AS prev ON prev.photo_id < photos.photo_id
    WHERE photos.photo_id = <photo_id to display here>
    ORDER BY photos.photo_id ASC, prev_id DESC LIMIT 1