jQueryMobile or “Mobile site” selection sets

Using jQueryMobile for a fairly lightweight “mobile site”, I wonder what all you experts say about selection sets. A (long) list of countries for example. To prevent excessive delays, I now split country selection in two screens. The first one shows A-Ö (A-Z for you English-speaking people), if I tap on B, the next screen shows a list of countries starting with B. Hitting the back button brings me back to A-Ö (A-Z), selecting a country takes me to.

It feels right, and it doesn’t transfer massive amounts of data that a) isn’t used half of the time, and b) doesn’t take time to render on slower mobile devices.

I’m not too concerned with database performance on the server for this particular selection set since the SQL query is static and resides in the cache 99.5% of the time.

Bye bye NetBeans, still fails on remote projects, cannot detect source file changes

So NetBeans 7.x is out since a few months. With many new functions, new and updated plugins, a lot of bugfixes, etc. Fantastic! Go NetBeans!

And just because I’m a sucker for punishment, I open up a new PHP project, select a WordPress site where I do some plugin sandbox development, enter all the parameters NetBeans wants, and click “OK”.

And … NetBeans starts doing its normal routine of scanning the remote (via SSH) directories, asks me to confirm that I want to download some 1714 files to my local computer, and when I do (why wouldn’t I, right?), it begins its glorious work.

In the meantime, I set-up a new project using ActiveState’s Komodo 6.13 IDE, I point it to the same server and directory and click “OK”. Three seconds later, I have my project.

NetBeans you ask? Oh, it’s still downloading. My Internet connection is too slow (it’ll max out around 20 mbit/s) of course .. I should have at least 100 mbit/s, or possibly GB/s. Because if you want to do NetBeans development on remote servers and do it the “proper NetBeans way”, you STILL have to download your entire project locally.

I could live with that rather awkward way of doing things if NetBeans could only detect changes to the file(s) on the remote. As it is now, and as it has been for many years with NetBeans, it’ll simply consider itself to be the master, and overwrite whatever is on the server.

Of course I’m doing it all wrong. I should use version control, I should not expect myself to be able to use my workstation as a terminal to the server. I mean, those days are gone, right? We ARE in the MODEM ERA of Internet, where you REALLY wanted to do EVERYTHING LOCALLY due to bandwidth limitations, etc.

Oh no, wait .. this is 2011 .. everyone but your pet is connected 24/7/365.

So, I think now that NetBeans have shown (again), that they have no intention of EVER fixing this problem, I’ll just do rm -r -f and be happy. And what’s more, so will the rest of the NetBeans community, because they won’t need to listen to me whining about it 🙂

Bye Bye NetBeans.

#NetBeans #IDE #PHP #fail #SSH #remote #development

Increasing the phpMyAdmin session timeout

When phpMyAdmin is installed, the default session timeout value is too low for many users, making your phpMyAdmin session expire too soon. One could argue that a low session timeout value is a good idea from a security perspective. If you do not think this is an issue, here are a few simple steps that’ll let you change how long phpMyAdmin will keep your session(s) alive.

Open config.inc.php in the phpMyAdmin “root” directory. Look for a line that contains this: $cfg[‘LoginCookieValidity’]. Set the value to the desired number of seconds you want the session to stay alive (3600 = one hour, which is reasonable for most users). If you do not have that line in your config.inc.php file, add it like this:

$cfg[‘LoginCookieValidity’] = 3600;

Don’t forget to save the file, and then login again to phpMyAdmin. You may need to close the browser and re-open your phpMyAdmin URL.

This also assumes that the PHP session garbage collection is set-up accordingly. This can be done in a number of ways:

  • php.ini; add a line (or change an existing) that contains session.gc_maxlifetime = <seconds>
  • Apache configuration; add a line to the appropriate <Directory> block that says “php_admin_value session.gc_maxlifetime <seconds>”
  • config.inc.php (phpMyAdmin); after the previously edited line, add a line with “ini_set(‘session.gc_maxlifetime’, <seconds>);”

The <seconds> above is the same value that you set your variable to in config.inc.php at the beginning of this post, “3600” (sans quotes) in my case. (Some of these methods may or may not work on the server you’re using.)

This isn’t the only way to circumvent phpMyAdmin sessions expiring on you in the middle of that important work; you can, of course, configure phpMyAdmin to have appropriate access directly, thus allowing you to access your MySQL database(s) without entering a username and a password. You’ll find more information about this on the phpMyAdmin website.

(phpMyAdmin is, IMHO, one of the best tools ever written in its class. My only gripe is that I’d really like to have a much less bloated visual display theme as the default, but you can accomplish this yourself quite easily.)

When version control systems fail miserably

When I began using version control system software, the world was mostly stuck with RCS, if you wanted to use free software that is. Next came CVS, PRCS, SVN (Subversion), Bazaar, Git, Mercurial, and many others. There were, of course, also many commercial version control systems available such as ClearCase and Perforce. So now we have several excellent pieces of software when it comes to version control.

In most cases, users of these version control systems seem to fall into two categories. Those that prefer to work locally on their own machine or in their own environment, and those that work in a shared environment. Regardless of which category you fall into, the theory behind many modern version control systems is that you never work against the immediate source, but instead use some sort of local version, be it “working copy” or “cloned repository”.

With the advent of integrated development environments such as Eclipse and Netbeans (and many others), support for version control systems is often built-in or provided via some plugin. You get immediate notifications when your source files have been modified (by yourself), when a conflict occurs, you can check files in and out of the repository, etc.

I — and others — seem to have run into a problem with the way things are being done, and I cannot seem to find a solution to this problem, other than resorting to the command-line interface of the various tools (svn, hg, git, etc).

Here’s my beef:

I keep a stable, production level, copy of a project at /home/prod/stable. It is reachable from the web (because that’s where I use the application) as http://www.somewhere.com/prod. It is also under version control at /home/repo/prod[..]

Now, I also keep my development version on that same server, also reachable from the web (because I don’t think duplicating my runtime environment on every single computer I may work on the project from is a grand idea). So for this, I have /home/prod/dev and http://www.somewhere.com/dev; I can choose to have a complete “duplicate” repository at say /home/repo/branches/dev, or just a working copy at /home/prod/dev. The crucial issue here is that I keep my live development files on the same server as the repo, but I code using NetBeans or Eclipse (or anything based on Eclipse) from my laptop or one of my workstations.

This combination seems impossible to get working if I want to use the built-in version control system support in either of these two IDE:s. I’ve gone through Subversive, Subclipse, SVNkit, Git, and Mercurial — and none of them, in combination with NetBeans or Eclipse, can handle this.

So I’m asking myself (and you) .. what’s f-ing problem?!? Why can’t NetBeans and Eclipse just treat the remote project as any other project? Why can’t I simply be allowed to create a remote project, and then specify the appropriate parameters for version control and be allowed to utilize the power of version control from within the IDE?

Using something like SSHfs to “trick” NetBeans and Eclipse into thinking it’s a local project won’t work either due to the really poor performance of SSHfs (Ubuntu 10.10). Obviously, the solution needs to handle not just me working on the same project from many locations, it also has to support other developers working on the same project, from many locations. All Eclipse-based editors (EclipsePDT, Zend Studio, Aptana, etc) suffer from the same problem since they use the same plugins.

Searching the web for this issue, I’ve come across many requests for this, but not a single solution; which, given the nature of Internet, is a pretty rare thing. I could never in my wildest imagination (and it’s pretty far out) had thought that I’d be having a beef with something as common as a remote server or remote file system in the year 2010 🙁

Why Netbeans 6.9x+ is an awesome PHP development environment

I’ve been doing some form of coding since around the advent of the IBM PC and VIC-20 and have obviously come across many editors and IDE:s for a number of platforms. Things have come a long way since Edlin. I cannot recall every single editor and IDE I’ve been toying with, and I’m not sure it’s relevant to this post, but some of them include A/Edit, Emacs, TSE/Qedit, Brief, SlickEdit, vi, and many derivatives of these. Having been a DOS programmer for quite some time, I’ve also been working in the various Borland IDE:s.

In the past 10 years I’ve mostly been using Emacs, and every now and then I’ve been sneaking a peek at various other Linux based editors. For the past several years I’ve been giving both Eclipse and NetBeans a go. There are a number of IDE:s out there that are based on Eclipse (Zend/ZDE, Aptana Studio, Eclipse PDT to name a few), so in many cases they share their core behavior, look ‘n’ feel, pros and cons.

One thing I’ve learned, the hard way, is that there are just about as many “My editor is better than your editor”-battles being fought as there are “My language is better than your language”-battles; programmers and developers truly seem to enjoy trying to outdo each other when it comes to proving their arsenal of tools to be superior to that of others. I’ve never understood this part. If you can solve the given task, with all its parameters, with whatever tools you prefer, go and do it. If someone else can manage the same thing with some other tool, good for them. Listening to these arguments is like listening to two five-year-olds battling it out trying to convince the other that a given color is prettier than another. Of course, one could just turn a deaf ear and not listen 🙂

Now let’s talk a little bit about Eclipse and NetBeans.
Continue reading Why Netbeans 6.9x+ is an awesome PHP development environment

Free CakePHP E-Book – Super Awesome Advanced CakePHP Tips

There are a few books out for CakePHP development. The main problem with them is that they’re fairly old. There’s also a book on the way (2010) that has not yet been released. And then there’s Matt Curry’s completely free CakePHP book for those that have managed to grasp the basics of CakePHP and want a guide to somewhat more advanced topics.

One can only congratulate Matt on a great idea and implementation; and what’s not to like about a free book about CakePHP development?

An introduction to the book here: www.pseudocoder.com/free-cakephp-book/
Matt Curry’s original blog post about it here: www.pseudocoder.com/archives/2009/05/13/free-cakephp-e-book-super-awesome-advanced-cakephp-tips/
The book’s direct download link is here: www.pseudocoder.com/Super_Awesome_Advanced_CakePHP_Tips.pdf

More about CakePHP can of course be found on www.cakephp.org

Matt has also released a number of CakePHP plugins and code snippets here github.com/mcurry.

Thanks Matt!

Preventing access to backup PHP~ files in Apache

Many Linux command-line people use the VI editor; but if you’re like me and prefer Emacs, you often run into the “problem” that Emacs creates backup files using the original filename and appending a tilde (~) to the end of the filename. E.g. “secret.conf.php” becomes “secret.conf.php~”.

There are a number of ways to go around this, of course. One way is to configure a separate directory for each user where Emacs stores its backup files, and then make that directory readable only by the user.

Why is this a problem? Well, if you’re using Emacs to quickly modify PHP applications’ configuration files, like the database configuration file, you’ll leave a trail of .php~ files. These files are typically not parsed by the PHP processor, instead they are handled by the text file handler in Apache. Meaning, if I enter the url http://myverycoolsite.com/secret.conf.php~, Apache will gladly display its actual contents, just like if you were editing the file.

This can be prevented by using the .. configuration construct in Apache like so:

<Files ~ “\.(html\~|htmls\~|php\~|phps\~|php3\~|php4\~)$”>
  Order allow,deny
  Deny from all

Perhaps not the most elegant of solutions, but it works. It will result in an “Forbidden” response from Apache. Check out the Apache documentation for more details on this directive.

You can go back to sleep now 🙂

Nullifying pointers in PHP

Using pointers in PHP is quite useful at times; but it can also leave you dumbstruck with serious debugging on your hands. Consider this construct:

[code]for ($i = 0; $i < 10; $i++) { $p1 = null; if ($Buffer [$i]['type'] == 'scanthis']) { $p1 =& $Buffer [$i]['data']; } .. if ($p1 != null) .. }//for[/code]
This will in effect dereference and overwrite a given [‘data’] array member of $Buffer if [‘scanthis’] evaluates to true. But I still want to use “null” as an indicator to whether or not to do something.

So I replace the above with:

[code]for ($i = 0; $i < 10; $i++) { unset ($p1); <-- $p1 = null; if ($Buffer [$i]['type'] == 'scanthis']) { $p1 =& $Buffer [$i]['data']; } .. if ($p1 != null) .. }//for [/code]
This will destroy $p1, but not what it’s pointing to, and then it sets $p1 to null, just like before.

This is obvious when you look at it, and there are a number of other ways to accomplish what I describe above, but it had me stumped for a while 🙂