PHP
  Home arrow PHP arrow An Introduction to Sockets in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

An Introduction to Sockets in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 24
    2006-05-22


    Table of Contents:
  • An Introduction to Sockets in PHP
  • The basics of low-level sockets: developing an illustrative example
  • Reading and writing socket data: creating a simple web-based client application
  • Reusing the TCP server: defining the "createSocketServer()" function and "SocketServer" class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    An Introduction to Sockets in PHP
    ( Page 1 of 4 )

    Working with low-level sockets can be a painful task in PHP. Fortunately, PHP offers a nice library of socket handling functions to make your life easier. If you do a lot of network programming in PHP, you will want to check out this three-part series, which starts with the basics and takes you through more advanced approaches. This article is the first one in the series.

    Introduction

    In the vast and exciting terrain of network programming in PHP, working with low-level sockets can be a cumbersome task. Most of the time, when you are developing a Web application, you do not go very deep into the manipulation of the lower-level features of a network operating system.

    If you've been using sockets in PHP, you probably know what I'm talking about. Writing, reading and controlling socket streams can be achieved well enough with the help of a comprehensive set of native PHP functions, such as the popular "fsockopen()", and "fputs()/fgets()" functions, and eventually the use of an iteration routine. This sounds relatively simple, and certainly will suit most of your socket programming needs. However, there are times when the requirements of a specific PHP project demand using low-level sockets, in order to implement, for example, a testing TCP-based server, and the corresponding client applications that will interact with it.

    In order to tackle this kind of situations (and many more, by the way), luckily PHP offers a nice library of socket handling functions, which can be used to create server and client applications, manipulate data streams, and perform many more tasks related to low-level network programming. With reference to using sockets in PHP, in this three-part series, I'll try to cover their most crucial aspects. I'll start with the basics, such as creating, opening and closing a socket. Then I will proceed to using advanced approaches, such as implementing socket servers. Of course, I'll accompany this material with numerous hands-on examples.

    At the end of this series, you should be equipped with a good grounding in how to use and manipulate low-level sockets in PHP, in order to expand your existing background of network programming.

    Now that you know the topics that will be discussed over this series, it's time to leap forward and begin learning the fundamentals of low-level sockets in PHP. It's going to be instructive, so let's get started.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek