Archive for May, 2009
PHP Script to get HTTP Status number
by z3n on May.08, 2009, under Coding, Tips & Hints
Problem:
Getting HTTP Status from a remote page.
Solution:
-
function cget_info($url) {
-
$ch=curl_init();
-
@curl_setopt_array($ch,array(
-
CURLOPT_URL => $url,
-
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 5.1) Gecko/2009042316 Firefox/3.0.10",
-
CURLOPT_RETURNTRANSFER => 1,
-
CURLOPT_VERBOSE => false,
-
CURLOPT_TIMEOUT => 5,
-
CURLOPT_MAXREDIRS => 0, // this will catch 302's
-
CURLOPT_RETURNTRANSFER => true,
-
CURLOPT_FOLLOWLOCATION => 1
-
));
-
@curl_exec($ch);
-
$r=curl_getinfo($ch,CURLINFO_HTTP_CODE);
-
curl_close($ch);
-
return $r;
-
}
-
-
echo cget_info("http://www.overflow.biz"); // 200
-
echo cget_info("http://www.overflow.biz/dfkjds"); // 404
-
-
?>
Restarting gnome-panel
by z3n on May.08, 2009, under Linux Happyness
Problem:
You followed the previous post and sucessfully installed Hardware monitor applet on your gnome, however it’s not showing. This is happening because gnome-panel didn’t updated it’s applets list, so you need to restart gnome-panel.
Solution:
There’s no cool way to do this, you need to kill the process, it will restart after that.
pkill -9 gnome-panel
Gnome hddtemp/sensors applet
by z3n on May.08, 2009, under Linux Happyness
Problem:
Monitor hardware, harddisk and other temperature, voltage and fan.
Solution:
yum install lm_sensors hddtemp gnome-applet-sensors
run sensors-detect to detect hardware sensors
then edit /etc/sysconfig/hddtemp and add your disks there
for multiple disks, example:
HDDTEMP_OPTIONS=”/dev/sd[abcdefg..]“
then you just need to run hddtemp and lm_sensors as deamon and done!
Note: if can’t see the Hardware monitor applet at gnome, read this.
Source:
last-modified headers missing!
by z3n on May.07, 2009, under Coding, Tips & Hints
Problem:
last-modified headers are missing on your httpd servers responses.
Solution:
This is happening because the page you’re testing is being taken as SSI, meaning that it’s being processed in the server first.
I really like to use SSI on my pages, even if they are static, it’s much easier to build them, since the headers and footers are usually all the same, and it’s much easier when you need to modify one of those, editing 2 files changes the whole site.
While building a sitemap script i noticed that server wasn’t returning the last-modified header, which is crucial for the sitemap xml to work right.
After some digging i found out about the XBitHack apache feature, which is able to return the last-modified header, even for cgi scripts.
You can enable this on the server config or on the .htaccess, for me, it was better enable only on the .htaccess, since this might cause unexpected issues and slowdown on the server, as apache site meantion, this last-modified date for SSI pages is harder to be pooled and uses more cpu.
So the solution is simple:
XBitHack On
in some cases you would need to enable it full,
XBitHack Full
This will make the files with execution mode enabled (chmod +x) to have a last-modified header on it, the full mode will enable group checking as well. Check apache docs for more info.
Sources:
Other usefull info:
Bonus:
Little script to show headers of a page (use it on prompt, php script.php <url>):
<?php
$fp=fopen($argv[1],”r”);
print_r(stream_get_meta_data($fp));?>
Tar over SSH (Pipe Tar)
by z3n on May.05, 2009, under Linux Happyness, Tips & Hints
Problem:
Copy over 10 million files to a different server perserving the permissions, ownership, paths etc.
Solution:
tar -zcf – /path/to/local/dir | ssh remoteuser@remotehost.tld tar -C /path/to/remote/dir -zxf -
this will send a compressed (z parameter) stream to stdout (-) wich will be sent by ssh and uncompressed on the remote server. If you are on a local network you can supress the z parameter in order to keep it faster.
Many people would say that rsync is a better solution, however, rsync don’t work well with many files, specially million files. rsync tends to do a checksum of each file and time/date comparsions which slowdown the process and create lots of disk I/Os, in my case, it was impossible to rsync, the remote server loads were so high that it eventually got stuck and crashed. Tar wasn’t only faster but more effective, making the server able to serve pages while doing it.
Tar will also preserve the ownership and permissions of the files, just what you need to have an exact copy.
Sources:
Monitoring Disk I/O
by z3n on May.03, 2009, under Linux Happyness
Problem:
How to know if the disk i/o is too high?
Solution:
There’s a couple of tools you can use for this, mainly:
vmstat , iostat, svmon, lslv, filemon
More Info:
Knowing when SELinux is enabled
by z3n on May.02, 2009, under Linux Happyness
Problem:
how to know when SELinux is enabled, disabled or on permissive mode.
Solution:
getenforce