I just came up with a word. It’s mostly used as a phrase, but I think it can be worded. Dupsorry. And I define it as an apology for a possible duplicate. For example, when you share a bookmark twice, or tell the joke you already told. It’s good to use it when you are not sure if you’ve just created a duplicate. Just in case. Enjoy!
The company that I work for is going through an amazing growth period right now. As a result, quite a few things change, re-shape, appear and disappear. Starting to lose the grasp in some areas, I decided to read more about organizational structures. Before reading, I thought about it for a bit. I tried to summarize everything that I know about the subject – both from personal experience and from the long forgotten textbook paragraphs. Once I started reading, I realized how little I actually know about this stuff.
It’s actually a fun little exercise. Pause for a minute and try to list as many different organizational structures that you can think about. Think. Think. Think. List. Hierarchical is the first one on the list. Right? It was for me. Then I spent some time thinking about all possible modifications to a hierarchy. And than my mind went empty.
That was too early to give up. Suddenly I remembered Google and that I read in quite a few places that they actually use a matrix organization. I knew that I read about it before, but couldn’t remember what it was and how it worked. Just in case, I added matrix organizational structure as number two on my list.
At that point, all clear thoughts stopped. As the last resort I remembered a well-known book “The Cathedral and the Bazaar” that I read a few years ago (the book is free and I strongly recommend you read it, especially if you have anything to do with Open Source Software). The cathedral is something very similar to a hierarchy that I thought of first. But the bazaar seemed like something that I didn’t have on my list. Even though the “organizational” part of this structure is questionable. I added it anyway. So my list got to three items.
And then I gave up. It was too much of an effort for too late of an evening. How many did you get? Did you get the same ones or different? Are you a business administration major? And if you are, what the heck are doing on this blog? Oh, no, you are welcome to stay – I am just surprised that you are here.
Anyway. It’s time to educate ourselves on this fascinating subject. And when it comes to quick education, Wikipedia is at the top of my list. Together with Google. There is a page on Organization, which provides a useful overview, with few more structures that I haven’t thought about. Of course I knew about committees and juries. It just didn’t come to my mind. And once I read about ecologies, I understood what they are and even remembered a few examples. So, I sort of knew about them too. Then, for even more details and examples I read the Wikipedia page, which is dedicated to the subject of Organizational Structures. That’s a bit difficult to process if you are sleepy, late in the day.
While I’ve definitely learned something today, the biggest benefit of the above Wikipedia pages is that they will provide me with me enough confidence to argue with my friends for hours upon hours over pints and pints of beer. Hopefully, that was as useful for you too.
There are a number of ways to monitor PHP errors, warnings, and notices. You can have your application code trigger some error handling, you can use PHP built-in methods, you can have some scripts running in the background analyzing logs, etc. While you already probably do some of it, here is something that you’ll find handy.
First of all, don’t log all PHP noise into a single file. You can easy make separate logs for each project. Somewhere at the top of your project, when it only starts loading, add the following configuration settings:
ini_set('error_reporting', E_ALL); ini_set('log_errors', '1'); ini_set('error_log', '/path/to/project/logs/php_errors.log'); ini_set('display_errors', '0');
This will enable logging of all errors, warnings, and notices into a file that you specified. And, at the same time, it will disable the display of all the logs to your visitors (something that you should definitely do for a production server).
One you’ve done that, you’ll notice another problem. If your application is of any considerable size and/or if it uses a lot of third-party code, you’ll get buried in all those warnings and notices. The file will quickly become very large and boring and leave your attention span. Not good. While you can fight the size of the file with a tool like logrotate, the boredom is a more serious problem. The same notices and warnings appear over and over and over. You’ll fix some of them and the others will stay there forever. What you need as a way to have a quick overview of what is broken and what is noisy.
Today I wrote a quick cronjob to do just that. Here it is in all its entirety.
#!/bin/bash # This script parses the project PHP errors logs every hour, creates the summary of all # errors/warnings/notices/etc and emails that summary to the email specified below. EMAIL="email@example.com" SUBJECT="here.com PHP errors summary for the last hour" PHP_ERRORS_FILE="/path/to/project/logs/php_errors.log" # The log starts with timestamp like [01-Mar-2010 12:48:56]. Timestamp + 1 stamp occupy about 24 bytes ONE_HOUR_AGO=`date +'[%d-%b-%Y %H:' -d '1 hour ago'` # We only need that double backslash because date pattern uses square bracket grep "^\\$ONE_HOUR_AGO" $PHP_ERRORS_FILE | cut -b 24- | sort | uniq -c | sort -n -r | mail -s "$SUBJECT" $EMAIL
You can drop this file into /etc/cron.hourly/report_php_errors.sh, change permissions to executable, and wait for the next run of hourly scripts. If you’ve updated the variables inside the script to reflect the correct email address and path to log file, you’ll get an email every hour which will look something like this:
From: firstname.lastname@example.org To: email@example.com Subject: here.com PHP errors summary for the last hour 14 PHP Notice: Use of undefined constant PEAR_LOG_DEBUG - assumed 'PEAR_LOG_DEBUG' in /some/path/to/some/file.php on line 17 12 PHP Notice: Undefined index: is_printed in /path/to/something.php on line 2035 9 PHP Notice: Undefined index: blah in /some/foo/bar.php on line 42 7 PHP Notice: Undefined offset: 1 in /some/verifier/script.php on line 120
The email will not be limited to 3 or 4 lines. It will actually contain each and every individual notice, error, and warning that occurred during the last hour in your project. The list will be sorted by how often each warning occurred, with the most frequent entries at the top.
With this list you can start fixing your most frequently seen problems, and you can also notice weird activity much faster than just checking the log file and hoping to catch it with your own eyes.