Call to a member function on a non-object error in Symfony2

There is this error that I was having trouble with in my project. It was an implementation of ZeroMQ and RatchetPHP on Symfony2. The web socket service I did was keep on crashing caused by this error

Error: Call to a member function broadcast() on a nonobject

The command it was executing was $topic->broadcast($msg). I tried doing a try catch but the error still occurs. After some reading, seems that the issue was on the variable $topic. Next thing I did was to check of what type was the variable $topic by:

echo get_class($topic) and it returned ‘Ratchet\Wamp\Topic‘.

After determining it’s correct type, I added a condition to check before doing the broadcast if it was of the correct object type:

if(is_a($topic, ‘Ratchet\Wamp\Topic’)) { $topic->broadcast($msg); }

Now, the service doesn’t crash anymore. Seems that at times it was returning a NULL object class when the $msg was actually empty.


Creating custom systemd Service File

I had a requirement at work where in I need to create linux systemd custom services. But when I try to enable them by “systemctl enable abc.service”, an error is displayed:

“Failed to issue method call: No such file or directory”

Normally, we look for these custom files in the /etc/systemd/system/ directory and everything should work, though not sure why it doesn’t work now. Based on a post I read, systemd would look at the /usr/lib/systemd/system as well. So what I did is I added my custom service files in that directory, run “systemctl enable abc.service” again and alas! it did work. It is somehow a dirty solution but it did fix my problem, whew.



MySQL Proc Crashed

One day when I powered up my machine, I had a trouble with accessing my database. After tailing on the logs, I found this error : Table ‘./mysql/proc’ is marked as crashed and should be repaired. Based on replies from forums, my database has been corrupted and needed fix by myisamcheck, assuming mysql data directory is on /var/lib/mysql/mysql:

myisamchk -q -r /var/lib/mysql/mysql/proc