Gossamer Forum
Home : General : Perl Programming :

help to conver 3 lines of PHP to Perl

Quote Reply
help to conver 3 lines of PHP to Perl
Hello this is my first post in this forum,I hope I can stay here for long and learn things from you guys.

I have added a PHP code to first line of my PHP script , which prevents the scrtip be runned if "Server Load" be more than 5
(server load shows how busy the CPU is) ,

I have a PERL script too, and I want to add that code to the begning of my PL script too, please kindly cover this PHP code to Perl for me .
PHP Code:
Code:
<?php
$LoadAvg = substr(file_get_contents('/proc/loadavg'), 0, 4);
if($LoadAvg > 5)
{
echo "Server busy, try again some minutes later.";
}
else
{
//Run Script.


}
?>





Thanks in advance.
Quote Reply
Re: [johnpaul] help to conver 3 lines of PHP to Perl In reply to
How about the following:

Code:

open
(FILE, "</proc/loadavg");
my $LoadAvg = substr(join('', <FILE>), 0, 4);
close(FILE);

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln

Last edited by:

dan: Feb 4, 2006, 11:31 PM
Quote Reply
Re: [dan] help to conver 3 lines of PHP to Perl In reply to
yes thanks it works it wont load the PL script when the loadaverg is more than 5 , but I dont know why it doenst print "the server is busy"
I added this code
Code:

open(FILE, "</proc/loadavg");
my $LoadAvg = substr(join('', <FILE>), 0, 4);
close(FILE);
if ($LoadAvg>1) {
print "server is buy";

}
else {

******SCRIPT Blah Blah***********

}

why it doenst print that "server is busy " ? have written print command wrong ?
Quote Reply
Re: [johnpaul] help to conver 3 lines of PHP to Perl In reply to
Try this (not Perl equivalent to supplied PHP code, but better):

open(FILE, "</proc/loadavg");
my ($a1, $a5, $a15, undef, undef) = split(/ /, <FILE>);
close(FILE);

$a1 = 1 minute load average
$a5 = 5 minute load average (the one you are interested in)
$a15 = 15 minute load average

load average varies between 0.00 and 1.00

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] help to conver 3 lines of PHP to Perl In reply to
hey I have added this code to a part of script ,

Code:
open(FILE, "</proc/loadavg");
my $LoadAvg = substr(join('', <FILE>), 0, 4);
close(FILE);
if ($LoadAvg>3) {
print "Server busy, try again some minutes later.";
exit;



it works well , when the server load is more than 3, it wont run the script **but** the problem is it WONT PRINT Line :
print "Server busy, try again some minutes later.";

it just shows a blank page , while I expect it print Server Busy...

here is the link to the Full source of my Script which is a CGI Proxy script .
http://www.about-ataturk.info/cgi-bin/nph-script.txt

if you want to find the code that I added to the CGI Proxy , search for this comment line :
# this is added by John Paul


I will be thankfull if you help me , I have had a lot of headache to make this CGI to run Print command
Quote Reply
Re: [johnpaul] help to conver 3 lines of PHP to Perl In reply to
I correctcted the link , you can access to the source here
http://www.about-ataturk.info/nph-script.txt
Quote Reply
Re: [johnpaul] help to conver 3 lines of PHP to Perl In reply to
In Reply To:
I correctcted the link , you can access to the source here
http://www.about-ataturk.info/nph-script.txt

Hello,
I have a question for you regarding PERL programing. This is for the 6 months project in Bioinformatics. My project topic is to download the protein complexes from the PDB website. Could you please guide me.
Thanking you,
-Bhaskar