Tales from a summer coder
the treasure chest of a geek
Tuesday, September 25, 2012
iTunes and Apple TV slowdowns with third party DNS
When I decided to look deeper into this problem, I found out Google DNS service was the cause (It is not Google's fault though).
Then I switched to Open DNS and everything turned into heaven again. But it looks like more and more Apple TV owners were switching to Open DNS as well. A few weeks later things went pretty bad to me again.
Now I am switching back to my ISP DNS which I hope will fix the problem permanently (or at least as long as it is up and running).
It doesn't only helps Apple TV to go faster, but boosts iTunes as well.
For a good explanation on why it happens, please read here.
PS: The DNS switch also had the benefit of fixing my iOS 6 Passbook, which wouldn't work even after the clock ugly hack.
Friday, September 16, 2011
Mac OS X 10.7 Lion and PHP
Since Lion upgrade, I have noted that sometimes the pager utility less was misbehaving. That's what happens when I try php -i | less:
th-png-dir=/BinaryCache/apache_mod_php/apache_mod_php-66.1~51/Root/usr/local' '--enable-gd-native-ttf' '--with-icu-dir=/usr' '--with-iodbc=/usr' '--with-ldap=/usr' '--with-ldap-sasl=/usr' '--with-libedit=/usr' '--enable-mbstring' '--enable-mbregex' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--without-pear' '--with-pdo-mysql=mysqlnd' '--with-mysql-sock=/var/mysql/mysql.sock' '--with-readline=/usr' '--enable-shmop' '--with-snmp=/usr' '--enable-soap' '--enable-sockets' '--enable-sqlite-utf8' '--enable-suhosin' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-tidy' '--enable-wddx' '--with-xmlrpc' '--with-iconv-dir=/:j
usr' '--with-xsl=/usr' '--enable-zend-multibyte' '--enable-zip' '--with-pcre-regex=/usr' '--with-pgsql=/usr' '--with-pdo-pgsql=/usr'
:j
Server API => Command Line Interface
Virtual Directory Support => disabled
:j
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /private/etc/php.ini
:j
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
:j
PHP API => 20090626
PHP Extension => 20090626
:
And that's what I would expect:
Build Date => Sep 16 2011 21:54:05
Configure Command => './configure' '--prefix=/opt/php536' '--enable-cli' '--with-libxml-dir=/usr' '--with-openssl=/usr' '--with-kerberos=/usr' '--with-zlib=/usr' '--enable-bcmath' '--with-bz2=/usr' '--enable-calendar' '--with-curl=/usr' '--enable-dba' '--enable-exif' '--enable-ftp' '--with-iodbc=/usr' '--with-ldap=/usr' '--with-ldap-sasl=/usr' '--enable-mbstring' '--enable-mbregex' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--without-pear' '--with-pdo-mysql=mysqlnd' '--with-mysql-sock=/var/mysql/mysql.sock' '--enable-shmop' '--with-snmp=/usr' '--enable-soap' '--enable-sockets' '--enable-sqlite-utf8' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-tidy' '--enable-wddx' '--with-xmlrpc' '--with-iconv-dir=/usr' '--with-xsl=/usr' '--enable-zend-multibyte' '--enable-zip' '--with-pcre-regex' '--with-pgsql=/usr' '--with-pdo-pgsql=/usr' '--enable-pcntl' '--with-gmp'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /opt/php536/lib
Loaded Configuration File => /opt/php536/lib/php.ini
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20090626
PHP Extension => 20090626
Zend Extension => 220090626
Zend Extension Build => API220090626,NTS
:
In both cases I tried to go down by pressing the key j five times.
At first I thought it was some change in a newer version of less so I was missing some command line option to make it behave like the old good way. But after spending an hour reading its manual, I was convinced it was not a feature - but a bug somewhere.
It turns out that Mac OS X 10.7 Lion (and other operating systems as well) comes with a borked libedit version. Unfortunately in that case Lion's PHP is shipped with libedit enabled, as we can see below:
$ otool -L `which php` | grep libedit
/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
So when you try to output PHP's stdout to less, libedit and less starts fighting for stdin in a not very healthy way - so you get a bad user experience (i.e. screen doesn't redraws well).
The first way I found around it is :
$ php -i < /dev/null | less
which is not practical in my opinion. The second way is to custom build PHP yourself:
cd /usr/src
# download and extract php 5.2.6
wget http://museum.php.net/php5/php-5.3.6.tar.bz2
tar -jxf php-5.3.6.tar.bz2
# go to source dir
cd php-5.3.6
# configure
CFLAGS='-arch x86_64' \
CXXFLAGS='-arch x86_64' \
LDFLAGS='-arch x86_64' \
'./configure' '--prefix=/opt/php536' '--enable-cli' '--with-libxml-dir=/usr' '--with-openssl=/usr' '--with-kerberos=/usr' '--with-zlib=/usr' '--enable-bcmath' '--with-bz2=/usr' '--enable-calendar' '--with-curl=/usr' '--enable-dba' '--enable-exif' '--enable-ftp' '--with-iodbc=/usr' '--with-ldap=/usr' '--with-ldap-sasl=/usr' '--enable-mbstring' '--enable-mbregex' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--without-pear' '--with-pdo-mysql=mysqlnd' '--with-mysql-sock=/var/mysql/mysql.sock' '--enable-shmop' '--with-snmp=/usr' '--enable-soap' '--enable-sockets' '--enable-sqlite-utf8' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-tidy' '--enable-wddx' '--with-xmlrpc' '--with-iconv-dir=/usr' '--with-xsl=/usr' '--enable-zend-multibyte' '--enable-zip' '--with-pcre-regex' '--with-pgsql=/usr' '--with-pdo-pgsql=/usr' '--enable-pcntl' '--with-gmp'
# build and install
make
make install
I usually do this as a regular user. You might want to give yourself permissions over /usr/src and /opt.
Also, note that Lion's PHP comes with a few improvements such as suhosin patch which we are not contemplating here.
Monday, October 12, 2009
Mac OS X 10.6 Snow Leopard, iPhone USB Tethering and Bad Carriers
You might think it is a small issue but I would say you can be wrong, sorry. Relying on carrier's default DNS can be very annoying when they are faulty. And thats exactly what happens with me all the time. My carrier DNS frequently stops resolving top hit domains such as google.com and many more.
Of course I can switch to bluetooth, in which case Snow Leopard "weirdly" allows you to set your own DNS. But keep in mind that sometimes the phone might have no battery for that. Again, I could just let the phone plugged in a power outlet and bring bluetooth up, but that would have any fun ! I like to have choices, and not being able to tether via USB is something that annoys me and challenged me for quite some time.
No more bla bla bla, I could fix my problem when I found about something called configd and scutil. You can find a bit of information about them here and here. Going straight to the point, I could manage to overwrite my default DNS (with the address for opendns) using scutil and a little of bash scripting. That is what I came up with:
#!/bin/sh
#
# Replaces current DNS with the one you want in Mac OS X
#
# Author: Igor Feghali
#
#DNS="208.67.222.222 208.67.220.220"
DNS="8.8.8.8 8.8.4.4"
STATE=`echo "list State:/Network/Service/[^/]+/DNS" | scutil | awk '{print $4}'`
(echo "d.init"; echo "d.add ServerAddresses * $DNS"; echo "set $STATE";) | sudo scutil
You can set the contents of the variable DNS in the above script to whichever you want. But don't get too excited. This solution will work only for a few moments. I guess that's because configd rebuilds the network configuration periodically.
A short visit to configd man page led me to the right place: /Library/Preferences/SystemConfiguration/preferences.plist stores the preferences for all the network interfaces. The first thing to do is to find out the HEX code of which one we want to modify.
That would be BB6EBCF-861B-4A73-94FE-E08F7EEEE5EE for me. Now open preferences.plist (in the above path) and look for the key string somewhere in the file between a <key> and a </key>. Now replace:
<key>EBB6EBCF-861B-4A73-94FE-E08F7EEEE5EE</key>
<dict>
<key>AppleTalk</key>
<dict/>
<key>DNS</key>
<dict/>
with:
<key>EBB6EBCF-861B-4A73-94FE-E08F7EEEE5EE</key>
<dict>
<key>AppleTalk</key>
<dict/>
<key>DNS</key>
<dict>
<key>ServerAddresses</key>
<array>
<string>208.67.222.222</string>
<string>208.67.220.220</string>
</array>
</dict>
Just be sure to edit the file as root ($sudo vim for instance), save and reboot. That should do the trick.
I couldn't manage to reload the system configuration without a reboot, just let me know if you do.
Monday, June 22, 2009
PHP'n Rio 09
The PHP Local User Group of Rio de Janeiro - PHP Rio are pleased to announce their 1st PHP'n Rio conference. It will be held July 03rd at theapplications built in PHP and testing code.
The keynote speaker is Jan Schneider that will talk about the Horde project. We will also have sessions about other frameworks and a PHP TestFest.
PHP'n Rio sessions goes from 6pm to 9pm. Then PHP TestFest follows up
to 10pm. No fees or subscription required. Participation is entirely
free !
Whether you live here or are around just enjoying the marvelous city,
come and join us :)
For more information please visit the official site (portuguese only).
We are looking for sponsors so we can bring even more speakers from
around the country while keeping a great conference for free. If you
see your company fits as our partner, please email Igor Feghali <ifeghali at phprio.org>
Saturday, March 7, 2009
PHP Test Fest 2009
What is it ?
The TestFest is an event that aims at improving the code coverage of the test suite for the PHP language itself. As part of this event, local User Groups (UG) are invited to join the TestFest. These UGs can meet physically or come together virtually.When is it going to happen?
UGs are free to pick any timeframe in April - June 2009. Each local TestFest can last a day, a week or any other timeframe.Where do I get more info?
At the official site of the event.Scalable logo for advertising
I used Inkscape to vectorize the official logo designed by Vincent Pontier, so you can make smaller/bigger bitmaps while keeping the good quality.
Sunday, December 21, 2008
Compiling SQLite 2 on Mac OS X 10.5 Leopard (for x86_64)
So we start with:
$ wget http://www.sqlite.org/sqlite-2.8.17.tar.gz
$ tar -zxf sqlite-2.8.17.tar.gz
The next big problem comes with CFLAGS. The package we are about to install comes with a pre-made configure script that doesn't respects the CFLAGS environment variable when creating the dynamic library. It took me a while but I have the patch for you, too.
--- configure.old 2008-12-21 18:50:24.000000000 -0200
+++ configure 2008-12-21 18:57:11.000000000 -0200
@@ -8253,7 +8253,7 @@
;;
esac
output_verbose_link_cmd='echo'
- archive_cmds='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs$compiler_flags -install_name $rpath/$soname $verstring'
+ archive_cmds='$CC '$CFLAGS' -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs$compiler_flags -install_name $rpath/$soname $verstring'
module_cmds='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
# Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's
archive_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs$compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
After applying the patch to the configure file we can proceed as usual:
$ ./configure --prefix=/usr/local LDFLAGS="-arch i686 -arch x86_64" CFLAGS="-arch i686 -arch x86_64"
$ make
I like to take full advantage of my system so I like to have things working at 64 bits. Just for the case I ever need a tool that won't go 64, I keep a fat binary with both archs 32 and 64. At this point we should check our work:
$ file .libs/libsqlite.0.8.6.dylib
.libs/libsqlite.0.8.6.dylib: Mach-O universal binary with 2 architectures
.libs/libsqlite.0.8.6.dylib (for architecture i386): Mach-O dynamically linked shared library i386
.libs/libsqlite.0.8.6.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
Everything seems fine. So we finally install it:
$ sudo make install
Monday, May 19, 2008
How to sync your Nokia 5200 with your Mac OS 10.5 Leopard
- Download the following plugin:

- Go to your Applications folder, look for iSync.
- Right click iSync, click "Show Package Contents"
- Navigate thru Contents\PlugIns\ApplePhoneConduit.syncdevice\Contents\PlugIns
- Extract here the zip you just got
- Enable bluetooth on your computer and phone
- Open iSync
- Press Command+N to configure your phone settings and you are done