Some time ago I noticed many messages in log file about named attempt to resolve strange addresses.
Continue reading “[Linux] “network unreachable resolving XXXX” messages in system log”
My site, devoted primarily to programming with my portfolio, articles, feelings etc.
Jan 09 2010
Some time ago I noticed many messages in log file about named attempt to resolve strange addresses.
Continue reading “[Linux] “network unreachable resolving XXXX” messages in system log”
Jan 06 2010
My search for a good PHP IDE never stops
My choice was Zend Studio until recently. But Zend Studio is not free and it’s free analogue – PDT – lacks some features like refactoring (PDT is also mainly developed by Zend, so, I think, Zend will always keep it low to prevent competition with Zend Studio). Also, it is monstrous (More than 300Mb installer) and it definitely lacks good Symfony support.
Recently I came across NetBeans, which is now free and developed by Sun. Sun seem to abandon all own IDE projects in favour of NetBeans, so this is a somehow strong foundation.
Oh… 25Mb installer only for PHP version
And… it is easy to use. Very. I would like to guide you through the creation of new symfony project in NetBeans.
Continue reading “Free opensource Symfony-friendly IDE: NetBeans 6.8″
Jan 06 2010
Recently, improving my WordPress plugin WP-SynHighlight, I chose EditArea as a source code editor with realtime syntax highlighting. The syntax of language description files for highlighting of EditArea is pretty much the same as Geshi has. So, I wrote a small converter and executed it over all Geshi files for 1.0.x version.
I have posted a patch for EditArea with all generated files.
So, now you can have EditArea with almost all power of supporting more than 130 languages
Jan 06 2010
Writting my WP-SynHighlight WordPress plugin, I came to a need of parsing multilined shortcode like this:
[ codesyntax option1="optionvalue1"...] <many lines here….> [ / codesyntax]
So, I extracted regular expression to parse shortcode from WordPress source code (if you are interested in it, see /wp-includes/shortcodes.php file). This regex was executed with /s option (PCRE_DOT_ALL) which makes dot (“.”) to match newlines also. There is no such option in JavaScript for some reason and I had to replace dot by such character class:
[\S\s]
Actually, any opposite metacharacters should work. [\W\w] for example.
Quite easy, isn’t it?
Jan 04 2010
Hello.
I’d like to share my script, which I use on some production servers for quick database backup using mysql tools. People say, that I should use bash for that, but I prefer PHP
Script uses mysqldump for dumping databases and gzip for compressing backups. rm is run to ensure backups are not stored for too long.
Continue reading “[Linux, PHP] PHP script to backup all databases”
Dec 27 2009
I’ve gotten cron log from one of my servers today which says:
/etc/cron.weekly/99-raid-check: WARNING: mismatch_cnt is not 0 on /dev/md0
That worried me a little and I decided to investigate.
Continue reading “WARNING: mismatch_cnt is not 0 on /dev/md0″
Dec 20 2009
Hello.
Here is a script, which I use on my production servers to secure them a bit. I hope it will be useful to you. Script logs all dropped packets so that you can easily find out tye clutch should there be any. Additional FTP server setup will be necessary. For ProFTPD add the following line to /etc/proftpd.conf:
PassivePorts 65400 65534
Jul 01 2009
Struggling with DDoS on my friend’s site, I wrote small Anti-DDoS script, that in original just lists all IPs, that have more than X active connections open to your server. It was originally written for FreeBSD.
#!/bin/sh
# Set here a minimum number of connections for action to be executed (150 by default).
FR_MIN_CONN=150
TMP_PREFIX='/tmp/frrr'
TMP_FILE=`mktemp $TMP_PREFIX.XXXXXXXX`
netstat -ntu -f inet| awk '{if(NR>2 && NF=6) print $5}' | cut -d. -f1-4 | grep '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' | sort | uniq -c | sort -nr > $TMP_FILE
while read line; do
CURR_LINE_CONN=$(echo $line | cut -d" " -f1)
CURR_LINE_IP=$(echo $line | cut -d" " -f2)
if [ $CURR_LINE_CONN -lt $FR_MIN_CONN ]; then
break
fi
# You can insert your own logic here (e.g. ban with your favourite firewall). Now it just prints the IP to console.
echo $CURR_LINE_IP
done < $TMP_FILE
rm -f $TMP_PREFIX.*I think this will work on general Linux also. You just need to change “cut -d.” to “cut -d:” in the listing and, probably, “/bin/sh” to “/bin/bash”.
Jul 01 2009
This is just an addition to my this article with some corrections needed if you use FreeBSD.
netstat command should look like
netstat -ntu -f inet| awk '{print $5}' | cut -d. -f1-4 | sort | uniq -c | sort -nr|more
And firewall IP blocking command should be
ipfw add deny all from xxx.xxx.xxx.xxx to any in
Jun 25 2009
Actually, I am using CentOS on production servers. CentOS native repository is very small and contains very necessary packages. If you need something more, you should consider using RPMForge repository as I do
But to add this repository to CentOS you need to do several annoying actions. And this is annoyng when you do so on each new server you are asked to setup. So, I wrote small script to automate the job which I like to share with you now.
Continue reading “[Linux] Automated RPMForge Repository Installation”
Jun 01 2009
My friend asked me to check the server with this problem. I did and of course first I checked free space on disk using ‘df -h’, but free space was ok. Googling around I found the reason. Unclean shutdown of Apache left many semaphores opened. So, I cleaned them with
for i in `ipcs -s | awk '/nobody/ {print $2}'`; do (ipcrm -s $i); done
You should replace “nobody” in the command with the name of the user Apache is running on your system under. Also I increased semaphore limit in /etc/sysctl.conf by adding to the end of this file
kernel.msgmni = 1024 kernel.sem = 250 256000 32 1024
No system restart is needed to apply changes. Just issue 'sysctl -p‘ command. The solution was found here.
You may also want to switch to another SSLMutex implementation.
Sep 19 2008
Introduction
Being a forum administrator/moderator on several forums I would like to share my opinions on how a good forum should be organized and administrated.
Continue reading “[Misc] A guide to effective forum administration v.0.9″
Aug 27 2008
Browing internet, I found the term of “quine” which is the program, that prints it’s exact source code. I was curious, if I am able to write such software. This is what I was able to compose:
<?php
$u='$';
$q="'";
$qq='"';
$s='<?php';
$e='?>';
$w='eval($p);';
$p='echo"$s\r\n{$u}u=$q$u$q;\r\n{$u}q=$qq$q$qq;\r\n{$u}qq=$q$qq$q;\r\n{$u}s=$q$s$q;\r\n{$u}e=$q$e$q;\r\n{$u}w=$q$w$q;\r\n{$u}p=$q$p$q;\r\n$w";';
eval($p);
It is a small and quite simple quine, however, I spent about several hours understanding how quines work and how to write them in PHP
Aug 25 2008
Recently I needed to quickly change charset on all tables and change each field’s chanset in each table in a specific database to latin1 and collation to latin1_swedish_ci. I googled a little and found this solution by shimon doodkin. I used it and it did work, but also it attempted to change charset at MySQL information_schema system database which is something I didn’t want to. It also proceessed all databases at MySQL server. Luckily, there was only two
It was a test server, that’s why I was uncareful.
Ok. I wrote a bit more elegant solution I would like to share with you today. It is pretty self-explanatory and is based on ALTER TABLE CONVERT TO charset MySQL statement.
Continue reading “[PHP, MySQL] Batch changing charset and collation on databases”
Aug 24 2008
As you probably know, latest software versions are rarely available to be installed as rpms. So, you need to compile them yourself. In this article I will briefly describe a process of installing, configuring and upgrading latest Apache and PHP.
Please remember, that installing from sources can sometimes break working system. So, please use this guide carefully.
Continue reading “[Linux] Installing latest Apache, PHP and MySQL from sources”
Aug 21 2008
YUM is an rpm package manager with very easy syntax. It is preferred especially for beginners to install packages using yum as this is very easy. Your Linux distro should already have yum by default, but if this is not so, let’s install it. BTW, you can find yum manual here.
You can check if your system has yum by entering
Continue reading “[Linux] Installing YUM (Yellow dog Updater, Modified)”
Aug 18 2008
My approach to writting mid-to-huge applications is to put each class to separate file and autoload class files on demand to eliminate the use of include/require statements completely. Autoloading in some cases can even speed up your project (for example, my scripts rarely throw exceptions. Exception classes are loaded by demand and only in case exception happend, so I remove
<?php
require_once('DatabaseException.php');
require_once('UserBOException.php);
overhead from my project. However, writting a good universal autoloader class is not trivial, however, simple. In this article I would like to suggest my own lightweigh multifunctional autoloader class.
Continue reading “[PHP] Writting Custom Class Autoloader Using SPL”
Aug 18 2008
Now PDO is most promising database access mechanism in PHP5. However, using PDO natively is not always convinient. In this article I will suggest my own lightweight wrapper for PDO calls, which simplyfies things for me. I am PHP5 fan, so we will use all object oriented technologies this language can give us in constructing our PDO wrapper.
Aug 11 2008
If you have many greedy users downloading files from your server using many streams per user, you can fight them easily with mod_choke Apache 1.x module. It is very easy. The article assumes your server is running under CPanel/WHM
Aug 11 2008
As you know, each time php script is executed, PHP interpreter need to compile it first to bytecode and only after that – execute. That compilation takes much time.
APC PHP extension (which will be included and enabled in PHP6 by default. It becomes a standard) can speedup php script execution process by caching once compiled PHP bytecode in memory. So, installing this extension increases your server performance (we assume you are doing this at CPanel/WHM controlled server). To install extension just do the following:
Continue reading “[Linux] Decreasing server CPU load with PHP APC cache extension”