Wednesday May 06, 2009

Zembly has announced that they will be having a blogging contest running until May 15th.  All you have to do is build some sort of widget or application with Zembly and write a blog entry about it like I am now.  Here is a link to the contest so get started building a widget for your chance to win $200 or a cool Zembly t-shirt.  

For those of you who aren't familiar with Zembly, it is "a new kind of application development environment that lends the power of the crowd to you, so you can do more, faster".  What this means is you can build widgets, services, and full social networking applications in the Zembly site while embracing the code that others have already created.  You can share code, collaborate with others, or just take code from another project to create your own widgets.  On the right side of my blog here you'll see the widget that I created.  It shows my different "tweets" from Twitter.  This was created very easily by using the built in Twitter API calls that Zembly provides.  There are many different API's provided for you already and Zembly has just added a great new feature allowing you to bring your own API to Zembly.

Zembly takes care of all the steps in building a widget starting with the web based IDE for writing your CSS, HTML, and JavaScript code but this isn't just an editor.  You have built in version control, code completion, an easy preview function, and much much more.  I build my Twitter app in no time using examples I found on Zembly.  Hosting is also taken care of because all of your apps and widgets are hosted in the Zembly cloud.  This is a great feature that allows you to build apps quickly and deploy them anywhere by injecting some HTML or JavaScript code.

Building widgets with Zembly is free so go give it a try, then blog about it and submit your widget to the Zembly team for consideration.  Here are a few more helpful links.

zembly.com
zembly.com/ui/competition/blog-contest
zembly.com/ui/about#what

Thursday Oct 09, 2008

I ran into an interesting problem with PHP on my Mac today.  I have been dealing with this issue for a while where connecting to MySQL with PHP only seems to work if I use 127.0.0.1 as the hostname and not if use localhost.  If I use localhost I was getting this errror:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'

Well today I decided to figure out why this was happening.  After researching a bit with Google I found a few references to the problem but no specific solution.  Then I saw a mention of using sockets vs TCP/IP to make the connection.  So it appears that when I specify the IP address (127.0.0.1), we are using TCP/IP to connect to MySQL.  But if I use the hostname localhost then we are using sockets.  Now apparently the MySQL default socket location is /var/mysql/mysql.sock but this is not the case on Leopard.  The actual location on Leopard is /tmp/mysql.sock.  There are several options to fix this and the easiest for me was to edit my /private/etc/php.ini and set the mysql.default_socket:

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /tmp/mysql.sock

Now, after restarting Apache, I can connect to MySQL with PHP using localhost instead of 127.0.0.1.  If you are looking for other solutions in case you can't edit your php.ini, here are the other options:

Taken from here.

   1. Create the /var/mysql directory (sudo mkdir /var/mysql) and then create a symbolic link from /tmp/mysql.sock to /var/mysql/mysql.sock (with: sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock).
   2. Edit /etc/my.cnf adding the following lines:
      [mysqld]
      socket=/var/mysql/mysql.sock
      [client]
      socket=/var/mysql/mysql.sock

      This will tell MySQL to create its socket where Leopard’s default PHP is looking for it. Next, you also need to create the /var/mysql directory and sudo chown mysql /var/mysql it or MySQL won’t start since it wont be able to create the socket.
   3. Recompile php for your version of MySQL (a PIA, but not a terrible idea at all).

Of these #1 is easiest, but a bit of a hack. #2 isn’t to bad, but could cause issues with other MySQL clients that look for the socket in /tmp/mysql.sock. #3 is ultimately the best fix, but is clearly neither very fast nor particularly easy

Wednesday Sep 10, 2008

I was playing around with the NetBeans PHP debugger on OpenSolaris and it was very easy to install and run.  It actually came with the new Sun Web Stack that I had installed, so there was really nothing to it.  However, it was a different story altogether to get XDebug running on my Mac.  There are no precompiled binaries from the creators of xdebug so your option is to compile from source or to search for a binary.  I am running Leopard, using PHP 5.2.6, and I started with the usual Google search for xdebug and leopard.  I found a few articles but it took quite a bit of trial and error and more Google searching until I stumbled upon a good solution so I thought I'd share my experience. 

When first searching you'll find articles that link to the Komodo IDE's precompiled binaries. This seems to have worked for a lot of folks because there are plenty of articles linking there and instructing you how to add the appropriate lines to your php.ini.  The steps are pretty simple.  Find the appropriate link on the Komodo page, download the zip and copy the xdebug.so for your version of php to your php extensions directory.  If you don't know where that is just open a php file with <?php phpinfo() ?> in it and you can find the extension_dir.  It isn't necessary to put xdebug.so in your extension directory because you need to specify the full path in the php.ini but I like to keep my extensions together for neatness and sanity purposes.  For example my extension directory is /usr/lib/php/extensions/no-debug-non-zts-20060613.  Once you've copied your xdebug.so file there go ahead and open your php.ini.  Again, if you don't know where it is, check your phpinfo(). 

 Add this line to your php.ini, making sure to replace the path with YOUR full path, somewhere near the other extensions just for sanity again.

zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so

Now restart apache and open your file with phpinfo() in it.  You should see a section for xdebug.  If you don't see it, open a terminal and type php -m.  This should show a list of modules.  Initially I was able to see xdebug listed with php -m but not in my phpinfo so I knew something was up.  I checked the apache error_log and found this line.

Failed loading /usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so:  (null)

This had me stumped for a while.  I tried a few things, nothing seemed to work.  Finally I decided I better compile the source myself.  I installed the latest XCode developer tools from Apple so I could run make, etc. Then I went back to Google to find some instructions for compiling xdebug.  Here is what I found that worked.

  1. Download the source code from http://xdebug.org/
  2. In the terminal, cd into the directory which the source code tar file is in
  3. Unpack the tarball: tar -xzf xdebug-2.0.3.tgz
  4. cd into the unpacked directory: cd xdebug-2.0.3
  5. Run phpize
  6. Configure: CFLAGS='-arch x86_64' ./configure --enable-xdebug
  7. Run make: make

I found these steps here.

Once you finish these steps copy the new freshly compiled xdebug.so from the modules folder to your extensions directory.  Replace the old xdebug.so and restart Apache.  Then run phpinfo() again and you should see the xdebug section.  This worked for me and I am now able to debug my PHP projects with NetBeans.  The funny thing is now when I run php -m I get the error about loading the xdebug.so extension but everything is working as far as Apache is concerned so I'm happy.