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

Brian Moon:
Using socket_connect with a timeout
Mar 12, 2015 @ 14:38:00

In a new post to his site Brian Moon has shared a problem he had with sockets and timeouts and having them perform the same way every time. He walks through the symptoms he was seeing and provides his own solution in the end.

So, it seems that when you try and connect to an IP that is routable on the network, but not answering, the TCP stack has some built in timeouts that are not obvious. This differs from trying to connect to an IP address that is up, but not listening on a given port. [...] After a lot of messing around, a coworker pointed out that in production, the failures were happening for an IP that was routable on the network, but that had no host listening on the IP.

After some testing, Brian figured out that his problem was using localhost for testing and not an actual non-host server. He made the switch and figured out how to set the timeouts low and work with error state checking to make things more stable. He explains a bit more about how the code in his solution works. You can find his solution in this gist on GitHub.

tagged: socket connect timeout issue stable consistent failure localhost

Link: http://brian.moonspot.net/socket-connect-timeout

Stephan Hochdörfer:
Configuring Xdebug and phpstorm for CLI debugging
Feb 11, 2015 @ 17:24:09

Stephan Hochdörfer has a quick post to the bitExpert blog today showing you how to configure Xdebug+PHPStorm for CLI debugging, making it even easier to work with command-line PHP applications.

Current situation: I have no local webserver running and just php5-cli (plus a few extensions) installed as most of the development I do will make use of a Vagrant machine. From time to time I develop small tools or libs which I like to debug on the command line. This is an overview how I configured my Ubuntu 14.04 box to handle debugging with Xdebug and phpstorm.

He starts with helping you get Xdebug installed (via PECL) and configured for local debugging. Next he adds some variables to the .bashrc configuration file with the IDE and Xdebug configuration details. Finally he gives the instructions to get PHPStorm to play nicely with this setup via it's own "Servers" support.

tagged: configure phpstorm debugging tutorial localhost server

Link: https://blog.bitexpert.de/blog/configuring-xdebug-and-phpstorm-for-cli-debugging/

Lorna Mitchell:
XHGui on VM, Storage on Host
Jan 05, 2015 @ 18:09:08

Lorna Mitchell has a new post today showing you how you can use XHGui in a virtual machine, sorting the resulting performance data on the VM rather than your local machine.

I'm doing some performance tuning on a project at the moment and my favourite tool is still XHGui - but it's designed to run on the same machine as its victim and since this is a vagrant VM, the chances of me destroying the machine and therefore the data are pretty high! Instead, I set it up to store the data onto the host and I thought I'd share how I did that. All these instructions for Ubuntu on both host and guest, and I've tried not to be specific about the vagrant elements in order to focus on how the pieces fit together rather than what you should type.

She walks you through all the steps you'll need to get the software up and running as well as configuring the actual guest VM to direct the data to the right place. She sets up the data source to push the results into (a MongoDB) and configures the PHP installation with an "auto prepend" of the XHGui header file. Finally, she includes the commands you'll need to view the data on the VM itself, running the built-in PHP web server as an ad-hoc instance on the VM itself.

tagged: xhgui xhprof mongodb vm virtualmachine tutorial localhost

Link: http://www.lornajane.net/posts/2015/xhgui-on-vm-storage-on-host

Konstantin Kudryashov:
Autohosts for Symfony projects on Mac
Oct 18, 2012 @ 15:39:43

Konstantin Kudryashov has posted a helpful hint for any web developer out there that knows the pain of constantly setting up VirtualHosts and local hostnames during their development. His suggestion makes setting them up simple using Apache2's "autohosts" support.

We all know, that web development is not as easy as it sounds and that it involves lot of different and sometimes really complex tools to just run or test stuff. We also know, that bootstrap (setup) of the project could take more time than you want it to. It’s not a big deal if you’re working on single project full time, but at KnpLabs, i’m bootstraping new sf2 project every 2 weeks. So this manual crafting of virtual host, edition of /etc/hosts and maintaining of those temp hosts everywhere made me really sick. So, at some point i’ve started to look for an elegant solution. Here is it.

He gives you all the commands, file contents and software you'll need to install (he uses Homebrew) to install dnsmasq and get it configured. The only Symfony-specific part of the process is the last step - getting the latest version of the framework and installing it.

tagged: autohost apache2 configuration virtualhost localhost automate

Link:

Arvind Bhardwaj's Blog:
How to Test PHP Emails on Localhost
Jun 09, 2012 @ 17:02:20

In this quick tutorial Arvind Bhardwaj shows a method for testing your scripts that need to send emails, but on your localhost system.

While developing web applications on localhost you must have always missed the functionality to send mails. As localhost does not support email service, so it has always been a bottleneck for email testing on localhost. But I have found a simple way to test emails on localhost using PHP. I have overridden the default mail() function of PHP to create a text/html file based on the email format. If the email is in html format, an HTML file is created otherwise a text file is created. You can see in this file what exactly is the content sent in your mail. See how does it work.

He shows how to override the mail function with your own custom "mail" function, just in a difference namespace. He includes the sample code to send the email (the "mail" function), a basic HTML template you can use and and example of it in use.

tagged: mail localhost email tutorial testing

Link:


Trending Topics: