iWatch is a perl script that uses inotify to monitor files directories. It’s similar to the watch tool, which can do all sorts of stuff if the files or directories it’s watching are modified or affected in pretty much any way at all.
Install iWatch
apt-get install iwatch
I’ve got this 1 liner in a file to quickly watch my directory and execute a PHP unit test .
I run this with a my argument (a unit test) and then sit there and code away. When I save, it detects the change and automatically runs my test. It’s pretty awesome.
I’ve run into a ton of issues working with crons, mostly with the $PATH variable screwing things up. Scripts work when run manually on the command line, but fail when run in cron. Very annoying.
I’ve asked a bunch of Linux sys admins how to fix this - and the answer is always “put the full path in your scripts” which to me in unacceptable as it introduces the possibility of human error. Fixing the underlying problem is always preferred.
I’m using PHP53 package from the IUS Community repository. I’ve been trying to get phpunit to install, but it gives an error that it needs DOM install. It took me a little bit to figure this out, but I finally got it working. What you need is the php53-xml package. You can install it using
yum install php53-xml
or if you’re using puppet
package { ["php53-xml"]:
ensure => present
}
And finally, to get it to install, I used the below. I had to make it go to multiple lines to fit on the page but I have it all on 1 line in my puppet script:
So, lets assume you’ve got a PHP project where you’re scraping pages and trying parse fields out of the DOM. Up till now, I’ve just used regular expressions because they’re easy. I avoided trying to parse html as xml using SimpleXML because there’s just to many cases where it would fail due to invalid tags.
Well, I feel like an idiot. It turns out there’s a great extension built into PHP to do just that, and it’s the DOM extension. Using this, parsing HTML with PHP is just as easy as accessing the DOM using JQuery. (hint: very easy).
This looks like a pretty cool tool to get a good idea of what’s going on in your PHP script without having to install tools like XDebug and Webgrind / KCacheGrind.
I’ll keep it short. In the last few days, login on our dev server broke. We hadn’t changed anything related to it, and everything looked good code wise. What we finally figured out was that our session cookie was set to expire 2 days into the future, and our VMWare image had lost 2 days of time.
I got this today. Solved by restarting the Memcached server. Move along.
Edit: this is actually a reoccurring bug we’re seeing with the memcache 2.2.3 stable build on 2 different boxes2nd Edit: Actually it was a bug in my code. I wasn’t setting the server and ip correctly, there was a typo in my configuration
If you do any work with single sign on, you’ll be familiar with the concept of exchanging tokens and validating against the authentication server using that token. One of the issues I’ve just run into which resulted in a huge headache is with urlencoding the result of a curl_exec that had a line ending. It’ easy to miss when it’s a longer string and you aren’t paying very close attention. This is a very simple example, and it still takes a second to realize there’s an extra character at the end.
Let’s get one thing out in the open. Curl is sweet. It does it’s job very well, and I’m absoutely thrilled it exists.
If you’re using curl in your PHP app to make web requests, you’ve probably realized that by doing them one after the other, the total time of your request is the sum of all the requests put together. That’s lame.
Unfortunately using the curl_multi_exec is poorly documented in the PHP manual.
I change the PATH variable in my .bash_profile to point to the /usr/local/python directory first, and source’d it to get the new PATH settings. Still get the same error.
If you manually call ob_start() at the beginning of your script, you might notice that you are unable to use phpsh. By commenting it out, I was able to fix the issue.
I don’t think it technically hangs, it just sits there with the data in a buffer waiting to be flushed.
In trying to get a site working on cell phones, I got a “406 Not acceptable” only on the Motorola RAZR. The site loaded fine on my Treo 755 and every Blackberry I’ve tried.
It seems that the RAZR doesn’t handle Multiviews very well, or at all for that matter. If you’re using Multiviews and Apache, you’ll have to specify the full URL: so /login.php rather just /login.
I’m migrating a PHP 4 site right now. It makes me realize how far PHP has come in the last few years.
I ran across a weird bug where code was working on our dev server, but not production. I was getting the error:
session_start(): Failed to initialize storage module
We’re using memcache to store our sessions, so it’s a user storage module.
Luckily, I stumbled across this helpful post.[edit: I only checked the page on our production box directly (not going through the load balancer) after I made this change, so it seemed to fix the problem, but the issue was really caused by the fact that I wasn’t defining the custom session handler when it was hit by the LB]
KCacheGrind is a very useful tool to identify bottlenecks in your applications. This will explain the steps to using it to find issues with your PHP scripts. For me, the scripts are all web pages.
I’m already assuming you’re running a current version of PHP. I did this using PHP 5.2.1. These instructions are based on a Unix/Linux server, if you’re running Windows I can’t help you.
I installed CentOS 5 on my VMWare a few days ago. I installed gcc via yum, compiled and installed libxml2. I then tried to install PHP 5.2.3 and received this error:
configure: error: installation or configuration problem: C++ compiler cannot create executables.
It took me forever to figure this out, but I had to install the g++ library, then it compiled fine.
Every now and then, we find that we will have a sudden increase in the number of apache processes, load average will spike up, and then go back down to normal. In rare cases, we will see the same thing happen, and the load avg spike WAY up, all queries appear locked up, and the server must be rebooted. I am looking for ways of determining what caused this. I should note that it happens extremely rarely, and has never shown up in a load test.
Regular expressions are awesome. However, sometimes doing everything in them is extremely difficult, or impossible. Luckily, we can flex the power of preg_replace’s ’e’ option to execute the replacement string as PHP code.
The reason why I found this is was I was looking for a suitable URL auto-linker that could shorten the url to a certain length. I found several examples on PHP.net, but unfortunately none of them did a good job of shortening the URL, or formatting it in a special way. This particular example is a simplified version of my auto-linker.
I saw a post on digg.com about how it’s nice to have “pretty urls” that are easy to tell people. While i’m not sure anyone would remember rustyrazorblade.com slash some ridiculous post name, it’s nice to have for search engines. Unfortunately, it didn’t really go into detail about how to accomplish the urls. A lot of people suggested mod_rewrite. Yes, it’s something you can use, but kind of a pain to set up.
I noticed after installing PHP 5.1.4 on my brand new MacBook Pro that my scripts weren’t executing. After about 3 hours of messing around, I realized that short_open_tag was turned off in php.ini.
Location: /usr/local/php5/lib/php.ini
Should be: short_open_tag = On
Not sure if this is a common issue, or if the PHP defaults have been changed. I installed the package distributed by Marc Liyanage, found at his homepage.
_Edit: According to the php web site, this should be on by default. _