 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Software Gunslinger: PHP is meant to die, continued
by Chris Cornutt 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.
voice your opinion now!
react die longrunning process testing socket server memory limit
PHPMaster.com: A First Look at React
by Chris Cornutt 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.
voice your opinion now!
react tutorial introduction nodejs socket server example
Segment.io: How to Make Async Requests in PHP
by Chris Cornutt 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.
voice your opinion now!
asynchronous request socket curl log queue tutorial
Nikita Popov: Cooperative multitasking using coroutines (in PHP!)
by Chris Cornutt 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.
voice your opinion now!
generator coroutine multitasking server socket tutorial
Christoph Hochstrasser: PHP Socket Programming, done the Right Way (tm)
by Chris Cornutt 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.
voice your opinion now!
socket programming extension tutorial client server
BinaryTides.com: PHP Socket programming tutorial
by Chris Cornutt 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.
voice your opinion now!
socket programming tutorial webserver bind
Tibo Beijen's Blog: Fixing mysqldump on Zend Server CE on OS X
by Chris Cornutt 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.
voice your opinion now!
mysqldump zendserver osx socket error fix
Joshua Thijssen's Blog: Creating a traceroute program in PHP
by Chris Cornutt December 02, 2010 @ 13:09:07
Joshua Thijssen has a new post to his blog looking at taking a common unix tool - traceroute - and seeing if he could translate it into PHP where it could be called directly without the need for something like exec.
Today i was reading upon this wonderful article about writing a trace-route program in Python in 40 lines. Even though trace-route is one of the many tools i use on day to day basis, i never really got into writing a version myself (something I like to do just to gain knowledge how things works). So when I was reading this post, i thought, Python is nice, but is it possible to do it in PHP as well? The answer to that: yes and no..
His post introduces you to "traceroute" (including a bit on how it works) in case you're either not a unix user or haven't gone much past some of the basics of the operating system type. One issues he butted up against was problems with the socket extension in PHP and inconsistencies with the underlying connection types. Another is the limitation of the tool only working as the root superuser. He includes the actual code and some sample output if you'd like to try it for yourself.
voice your opinion now!
traceroute program socket issue
|
Community Events
Don't see your event here? Let us know!
|