Paul's Programming Notes PostsRSSGithub

MySQL IF Statement Affect On Speed

if(`table`.`start`='0000-00-00','',`table`.`start`)

That’s the part of my query that was increasing the execution time by 10x.

I changed it to just `table`.`start` (without the IF statement) and the query was 10x faster.

Failed to connect to socket /var/run/dbus/system_bus_socket

Error: Can’t find out if NetworkManager is running: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory.

The following fixed the problem:

apt-get install dbus

(if you already have dbus installed: sudo service dbus start)

/etc/init.d/network-manager start

What caused the error?:

/etc/init.d/network restart

Could not initialize NMClient

** (process:17986): WARNING **: error: could not connect to NetworkManager

Fix: Try running with sudo.

For example: sudo nm-tool | grep DNS

Crontab Mistake

I wanted to run a script every 20 minutes, so I put this into my crontab:

20 * * * * sh script.sh

That’s wrong. That only runs it once every hour 20 minutes into the hour. For example, 20,40 * * * * sh bash.sh would run it twice - 20 and 40 minutes into the hour.

To run the script every 20 minutes like I was expecting:

*/20 * * * * sh script.sh

PHP Best Practices

https://phpbestpractices.org/

Things I learned:

  • It’s easy to install PHP-APC for quick opcode caching, and it apparently serves the same purpose as memcached for a single server.
  • Memcache and Memcached are two different libraries.
  • There’s a different (a small one) in speed between single and double quotes.
  • Use phpass to store passwords.