News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Saran Chamling:
Simple Chat Using WebSocket and PHP Socket
July 30, 2013 @ 10:38:41

While not a recent article, this post from Saran Chamling is definitely interesting. In it he shows you how to create a real-time chat by combining PHP and WebSockets.

The WebSocket is a feature of HTML5 for establishing a socket connections between a web browser and a server, once the connection has been established with the server, all WebSocket data (frames) are sent directly over a socket rather than usual HTTP response and requests, giving us much faster and persistent communication between a web browser and a server. Let's create a simple chat system using this cool technology (HTML5 WebSocket and PHP).

He includes all the code you'll need to get things up and running, starting from the WebSocket side. With a simple socket connection and some jQuery to control it, the system connects to the backend PHP script. The PHP script reads directly from the socket (using the socket_* functions) and binds to it, waiting for incoming requests. There's also some sample code showing how to work with the "handshake" between the WebSocket and PHP and how to respond. If you want something a bit easier to work with and more functional, consider checking out Ratchet, a WebSocket server for PHP.

0 comments voice your opinion now!
websocket realtime tutorial chat socket

Link: http://www.saaraan.com/2013/05/chat-using-websocket-php-socket

Software Gunslinger:
PHP is meant to die, continued
April 26, 2013 @ 09:15:56

In his previous post ("PHP was meant to die") the point was made that PHP isn't really designed as a language to handle long running processes very well. It's made to handle a few operations and then die at the end of the request. In this follow up post he talks more about using PHP for long running processes and a library that could help.

Yes, I already acknowledged that PHP has a garbage collection implementation starting 5.3.0 and up (opt-in or opt-out, that's not the problem). I also acknowledge that garbage collection works, and is able to take care of most circular references just fine. [...] Anyway, as previously stated too, garbage collection is a great thing, but not enough for PHP. It's a borrowed feature that does not play well with old fundamental decisions inherited from the original design. Garbage collection is not a magical solution for every problem, like many tried to argue about. Let's illustrate with another example.

His example uses the React PHP library (a non-blocking I/O platform) to handle a lot of incoming data to a port and report back some memory usage and limit settings. He explains a bit about what's happening and shares the results of the test, including the end result - a fatal error when the memory limit was hit. He still comes to the same conclusion, ultimately...PHP is just not the language to use for long-running processes that do any large amount of work.

0 comments voice your opinion now!
react die longrunning process testing socket server memory limit

Link: http://software-gunslinger.tumblr.com/post/48215406921/php-is-meant-to-die-continued

PHPMaster.com:
A First Look at React
March 26, 2013 @ 10:01:33

On PHPMaster.com there's a new tutorial that introduces you to React, the PHP-based event-driven non-blocking socket tool that's similar to some of the functionality Node.js provides. The article is a very basic introduction but can help get your feet wet with the tool.

For the past couple of years, Node.js has been drawing increasing amounts of attention as a promising web technology. While it has some strengths, like being event driven, some people just want to stick to PHP. For over a year now, however, there has been a similar project for PHP named React. React is mostly coded by Igor Wiedler, who is also a prominent contributor to the Silex framework. While reading through the React examples, it really does look similar to Node.js.

Included in the post are the instructions on how to get the latest version of React (via Composer) and the code to create a sample server that just writes out a string with a counter for the number of requests made. There's also an example of a "keystroke logger" for all data that's coming across the connection. The author (Igor) notes, however, that he wouldn't recommend using React in production, though, as its target is mostly those working with "cutting-edge technologies" rather than more stable applications.

0 comments voice your opinion now!
react tutorial introduction nodejs socket server example


Segment.io:
How to Make Async Requests in PHP
February 06, 2013 @ 09:52:49

On the Segment.io blog there's a new post by Calvin talking about making asyncronous requests in PHP and three different approaches you could use, depending on your situation.

When designing client libraries to send data to our API, one of our top priorities is to make sure that none of our code affects the performance of your core application. That is tricky when you have a single-threaded, "shared-nothing" language like PHP. [...] Ideally, we like to keep the setup process minimal and address a wide variety of use cases. As long as it runs with PHP (and possibly a common script or two), you should be ready to dive right in. We ended up experimenting with three main approaches to make requests in PHP. Here's what we learned.

Their three suggestions don't involve external dependencies (like a queue server) and can operate pretty quickly:

  • Opening a socket and closing it before waiting for a response
  • Write to a log file (a pseudo-queue)
  • Fork a curl process (through something like exec)

They each have small code examples included with them and explanations as to their plusses and minuses. For their needs, the "forked curl" solution worked out the best, but check out the other options too - you might have different needs.

0 comments voice your opinion now!
asynchronous request socket curl log queue tutorial


Nikita Popov:
Cooperative multitasking using coroutines (in PHP!)
December 24, 2012 @ 09:46:36

Nikita Popov has a new post to his blog about a new feature that will be coming in PHP 5.5 and how to use them, coroutines and generators, in an example application.

Coroutines on the other hand have received relatively little attention. The reason is that coroutines are both a lot more powerful and a lot harder to understand and explain. In this article I'd like to guide you through an implementation of a task scheduler using coroutines, so you can get a feeling for the stuff that they allow you to do. I'll start off with a few introductory sections. If you feel like you already got a good grasp of the basics behind generators and coroutines, then you can jump straight to the "Cooperative multitasking" section.

He starts with a look at generators, a piece of functionality that will allow PHP to, for example, more easily create iterators "on the fly." He then moves on to coroutines, added functions that you have two-way communication with generators instead of just pulling data from them. With the basics out of the way, he gets into the "cooperative multitasking" and a sample socket-based server he implements using some of the concepts.

0 comments voice your opinion now!
generator coroutine multitasking server socket tutorial


Christoph Hochstrasser:
PHP Socket Programming, done the Right Way (tm)
August 01, 2012 @ 10:16:15

In one of his recent posts Christoph Hochstrasser looks at socket programming done the right way, complete with code examples showing both client and server setups.

When writing about socket programming with PHP, nearly all articles are about the Socket Extension, despite it's the unfriendliest and most cumbersome way to work with Sockets in modern PHP. Let me introduce you to something, which apparently is pretty unknown among PHP programmers.

He starts off by introducing the concept of a socket (for those that are beginners on the topic) and talks about two of the major ways to work with them - the Socket extension and Streams. He shows how to use the stream_socket_client_* functions to connect to a remote server and make a HTTP request for the base page. He also shows the other side of things, making a simple "echo" server that binds to port 1337.

0 comments voice your opinion now!
socket programming extension tutorial client server


BinaryTides.com:
PHP Socket programming tutorial
July 24, 2012 @ 12:14:37

On the BinaryTides.com site there's a recent tutorial showing you how to effectively use sockets in your PHP applications, complete with incoming and outgoing examples.

This is a quick guide/tutorial to learning socket programming in php. Socket programming php is very similar to C. Most functions are similar in names, parameters and output. However unlike C, socket programs written in php would run the same way on any os that has php installed. So the code does not need any platform specific changes (mostly).

They start with the basics - creating a socket, connecting to a server and sending out information over the connection. They also include the code examples showing how to pull in data from the socket. Their example socket is set up to be a simplistic web server, returning data according to the standards for a normal GET request. They make a mini-server out of it, getting to to accept requests on a bound socket.

0 comments voice your opinion now!
socket programming tutorial webserver bind


Pavel Shevaev's Blog:
Make php-fpm execute arbitrary PHP scripts via socket
October 26, 2011 @ 11:19:23

Pavel Shevaev has a quick new post to his blog showing how to get PHP-FPM to execute PHP scripts via a socket request.

We are using APC cache very heavily in our projects and during project deployment the cache must be flushed and warmed up. A common solution to warmup the APC cache is to fetch some special page via HTTP which does the job. The problem with this approach is that it's not reliable enough when PHP is served via several fastcgi back-ends.

To solve the problem, he uses a PHP-FPM module to work with the FastCGI socket and execute any file (as permissions allow, of course). In his case, he uses it to "warm up" his APC cache for the user. A code snippet is provided as an example.

0 comments voice your opinion now!
phpfpm execute socket fastcgi module tutorial


Tibo Beijen's Blog:
Fixing mysqldump on Zend Server CE on OS X
March 01, 2011 @ 11:50:58

Tibo Beijen has a new post today showing his method for fixing mysqldump on Zend Server CE running on an OS X platform. The default install throws a socket error when you try to dump a database using the command.

Inspecting the mysql configuration contained in /usr/local/zend/mysql/data/my.cnf confirmed that the section [client] showed the socket as returned by executing SHOW VARIABLES; from the mysql client: /usr/local/zend/mysql/tmp/mysql.sock Although it is possible to specify the socket by using mysqldump's --socket switch, that doesn't really seem a 'solution'.

As a real solution to the problem was to copy over the my.cnf file from the custom location Zend Server has it in to the default "/etc/my.cnf" with settings pointing to the correct MySQL socket.

0 comments voice your opinion now!
mysqldump zendserver osx socket error fix


PHPBuilder.com:
PHP Scripts for Interacting with Networks
December 15, 2010 @ 13:49:31

On PHPBuilder.com there's a new tutorial showing you some of the PHP functions that you can use to interact with the network surrounding (and even vaguely related to) your application.

PHP has a great many tools for interacting with a network and also with the Internet. In this article, I examine some of those tools and functions to show how exactly you can use them to make your scripts more useful in a network environment. Click here to download the accompanying source code.

They show how to use fopen to access remote sites, gethostbyname and gethostbyaddr for DNS resolution, getprotobynumber to check the port number for a TCP/IP type and quite a few more. This also includes a brief look at the PEAR Net_Whois package. You can download the examples if you'd like to just jump into the code.

0 comments voice your opinion now!
network interaction tutorial tcpip socket dns



Community Events





Don't see your event here?
Let us know!


opinion testing introduction release language community experience threedevsandamaybe framework series interview list podcast symfony2 unittest refactor developer code laravel install

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework