I love Vagrant, its a great tool for development. Sadly, once your project gets too big, performance really drops off a cliff on Windows. Running a Symfony2 project, I was getting ~20 second page refresh times. Apparently this relates to VirtualBox NFS on the shared folder.
A few people mentioned using Samba instead of NFS, but I couldn’t find anyone who had successfully used it. I gave it a go, and can confirm, it works a treat.
So first off, ssh into your Vagrant box:
then install Samba and edit the conf file
apt-get install samba
sudo nano /etc/samba/smb.conf
and add in:
comment = Local Dev Server – /var/www
path = /var/www
browsable = yes
guest ok = yes
read only = no
create mask = 0777
force user = root
force group = root
after that restart the Samba server
sudo restart smbd
sudo restart nmbd
Then I copied all the files in my project to my new Samba share directory ( called in this case ‘shared’).
after that I edited my Vagrantfile to make sure the NFS share was definitely turned off.
config.vm.synced_folder “.”, “/vagrant”, disabled: true
I couldn’t seem to get the Solr Suggester feature to work from the official docs examples so thought I’d document my working example.
In my case I wanted to suggest locations based on data currently within the index.
<searchComponent name=”suggest” class=”solr.SpellCheckComponent”>
<requestHandler name=”/suggest” class=”org.apache.solr.handler.component.SearchHandler”>
and then schema.xml
<fieldType class=”solr.TextField” name=”text_auto”>
and in schema.xml fields:
<field name=”myFieldForAutocomplete” type=”text_auto” indexed=”true” stored=”true” multiValued=”false” />
<copyField source=”city” dest=”myFieldForAutocomplete” />
then its a simple case of building the index with a call to:
after that we can use suggest with:
Solr should then give you a nice response like:
Just for reference, here is the bootstrap.sh file I use to bring up my vagrant dev box with Solr 4 and Jetty ready to go.
apt-get install python-software-properties
apt-get install php5
apt-get install php5-mysql
apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
apt-get install phpmyadmin
apt-get install php5-curl
apt-get install -y apache2
apt-get install -y tomcat6 curl
rm -rf /var/www
ln -fs /vagrant /var/www
mkdir -p /opt/jetty/webapps/
mkdir -p /opt/jetty/webapps/
tar -xvf solr-4.4.0.tgz
cp solr-4.4.0/dist/solr-4.4.0.war /opt/jetty/webapps/solr.war
cp -r /opt/solr-4.4.0/dist /opt/solr
p -r /opt/solr-4.4.0/contrib /opt/solr
# copy new cores
cp -R /var/www/solr-config-master/solr-config-master/example solr
cp -r solr-4.4.0 solr
sudo sh tomcat6 start
sudo java -jar start.jar
Whenever a new Solr version comes out they tend to move the location , so a good idea to check whats’ what: http://apache.hippo.nl/lucene/solr/
I’ve never really come across the need to use an interface, and usually just use inheritance to extend whatever class I needed to. Recently though I needed a generic base caching class, which would have other classes implement there own methods.
public function getCacheValue($key);
public function setCacheValue($key , $value);
Note that there is no content within the methods, and rather than curly braces, its closed off with a ‘;’.
To implement the interface:
class CacheGoogle extends Controller implements CacheInterface
public function getCacheValue($key)
//try and get cached value from the DB
public function setCacheValue($key , $value)
//add new cache value to DB
Then wherever its needed:
public function __construct()
$this->cache = new CacheGoogle;
public function checkCache(CacheInterface $this->cache)
This week we had the director of an external agency in the office.
During a meeting with him he brought up that back in the old
days of cubicle programmers, some would have ‘cardboard cutouts‘ to bounce ideas off when they got stuck with a problem.
I mentioned that often when I was stuck with something and went to Stackoverflow to find a solution, often in the process of typing out and explaining the problem to someone else I’d come to the solution myself.
This weekend whilst sat in the sun reading The Pragmatic Programmer , I came to the section on ‘Rubber duck debugging‘ and realised that Stackoverflow makes a great rubber duck.
As it turns out Jeff Atwood thinks so too.