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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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? 
PHP

An Introduction to Sockets in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 20
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


       · This first article covers the most important functions related to creating,...
       · This one is the best tutorial i found on net.Good Work
       · Thank you for the kind comments on my PHP article. I really appreciate them and it's...
       · i comment over this topic previously it was great.i am using your server ex. to...
       · Thank you for commenting on my PHP article. Actually, I’m not sure to understand...
       · I was looking for an introduction of PHP network programming capabilities as I...
       · Thanks for the kind words on my PHP sockects article. Good to know it's been helpful...
     

       

    PHP ARTICLES

    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter
    - Building Your Own System Tray Application Us...
    - Structuring Your Projects for Web Applicatio...
    - Inserting, Updating and Deleting Database Ro...
    - Building Your Own Desktop Notepad Applicatio...
    - Web Application Security Overview
    - Working with the Active Record Class in Code...
    - Generate PDF Documents with PHP on the Windo...
    - Sending Email with PHP Networking
    - Performing Strict Validation with the Code I...
    - The preg_replace_callback() function in PHP
    - PHP Networking
    - Validating Web Forms with the Code Igniter P...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT