Skip to content

Fixing PHP short open tags

Find and replace in Eclipse PDTA PHP block is started with the tag <?php. However, there is also an alternative known as a "short open tag" which is to only use <?

The problem with using short open tags is that they conflict with xml parsers and for that reason, support for short open tags has to be enabled. By default, it's disabled and enabling deprecated features may be impossible if hosts don't allow it.

Every so often you may come upon a code base that was written using short open tags.

Often people are first confronted with this problem when they have a legacy code base, and either move it to a new server or upgrade php only to find that the site is spewing errors and no longer functional. In a worse case scenario portions of your php code will be plainly visible to end users due to the fact that the php parser is no longer parsing those blocks and simply returning them as html text.

There are a number of different approaches you can take to solve this problem. First you can turn on the support for short open tags, but as I mentioned previously, this is not recommended.

Continue reading "Fixing PHP short open tags"

How I found symbolic links for gitignore with find and cut

I was cleaning up a directory of old files for addition to git, and I came across a bunch of symlinks to a completely different codebase. In this particular case it was a wordpress blog that had a series of its files linked into the webroot of the site, that existed in an entirely different directory. I didn't want these files in the git repo.

Finding all the symlink files is easy enough.


cd /path/to/root
 


The find command gives us an easy way to get all symlink files:


find . -type l
 


But that's just a start -- we have to get these into the .gitignore file. Continue reading "How I found symbolic links for gitignore with find and cut"

Battle.net error code BLZBNTBNA00000640 (1201)

Whoops! Hmm, something went wrong with a security certificate.

Whoops!
Recently Conor has been playing WoW and we came across an issue where the battle.net client displays this error rather than the latest Blizzard news.

I think it's safe to assume that Blizzard used an embedded web browser control for this section of the application, and most if not all of the recommended steps they provide (restarting battle.net, reinstalling, etc.) aren't going to fix the underlying problem, which has to do with SSL certificate validation going on in the requested page. What did actually fix this under OSX, was deleting the certificate in question from the OSX keychain. Read the rest of this for the how to. Continue reading "Battle.net error code BLZBNTBNA00000640 (1201)"

Showing your git branch in your shell prompt

At some point I found some code to get the git branch name and insert it into the shell prompt. As it was some years ago, sadly I've forgotten the original source, but it wasn't exactly the type of prompt I'm used to, so I tweaked it until I got it the way I prefer. In the first set of brackets, I display the user@host:directory.

Once I cd into a git initialized directory a colored prompt appears with the branch name displayed in gold. For my purposes, this is simple, functional and doesn't result in overly long prompts. Here's what you can expect from any terminal that supports ansi color codes.



To implement the prompt on your server or workstation, simply cut this snippet and paste it into the end of the /etc/bashrc file.

The current way to do this is to create a new file named "gitprompt.sh" in the /etc/profile.d directory, and paste the code below into it. Using vim is a good way to accomplish this task. You need to be root or sudo for this to work of course.

Once the file exists, all the system users will benefit from the prompt in their shell sessions.

Using this prompt, whenever you're in your bash shell, there will be no question of whether or not you are in a git initialized directory, or what your currently checked out branch name is.


# Custom aliases and functions
function parse_git_branch_and_add_brackets {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
}
PS1="[\u@\h:\W]\[\033[0;33m\]\$(parse_git_branch_and_add_brackets)\[\033[0m\]\$ "
 


Does this work on a Mac? Yes of course!




Defined tags for this entry: , , ,

XDebug for developing, debugging and profiling PHP

XDebug is one of the essential PHP extensions for PHP developers. The name is a bit misleading, as it implies that it is just a debugging tool. This can put people off, since getting the debugger to work with your personal editor requires an understanding of networking, and can often be confusing. Even if you can't immediately get XDebug to work as a debugger, it is still valuable as a stack trace tool, or as a color coded replacement for PHP's var_dump, or as a code coverage analysis tool, and most importantly as a profiler. In this tutorial I'll attempt to cover installation, and most of XDebug's standard features.

Continue reading "XDebug for developing, debugging and profiling PHP"

system-switch-mail is gone, so use alternatives

When I setup a new Centos or Amazon Linux server, one of the first tasks I want to accomplish is installing postfix. There used to be a package named system-switch-mail that made this easy to do from the shell. If you've tried to yum install this package recently you might have been surprised to find that it has disappeared. Instead there is a tool that lets you do essentailly the same thing which is part of the chkconfig package.


For this to work you need to have the chkconfig package installed:

CODE:
[root@ ~]# rpm -qa | grep chkconfig
chkconfig-1.3.49.3-2.10.amzn1.x86_64


If you don't see it, then yum install chkconfig!

With chkconfig installed you have access to the alternatives system. Of course to be able to switch your mta you first have to install your sendmail alternative. In my case it's typically:


yum install postfix
 



Now you can switch your system to use postfix as the default MTA!


alternatives --config mta
 


Choose Postfix and hit enter and you're done. Don't forget to remove sendmail, as you no longer need it.


yum remove sendmail
 


Defined tags for this entry: