CVS

I feel it’s time to learn something new, so I chose to learn about CVS. I’ve seen it used by developers on their open-source projects. The developers of PHP are using this system to keep track of changes made by other developers.


CVS stands for Concurrent Versions System. A version control system where 2 or more developers can work on a single file without affecting one another. When both developers make changes on the same section of the file, an conflict occurs and the overlapping code is marked by the server. Either developer then has to manually resolve the conflict.


cvs also helps you if you are part of a group of people working on the same project. It is all too easy to overwrite each others’ changes unless you are extremely careful. Some editors, like gnu Emacs, try to make sure that the same file is never modified by two people at the same time. Unfortunately, if someone is using another editor, that safeguard will not work. cvs solves this problem by insulating the different developers from each other. Every developer works in his own directory, and cvs merges the work when each developer is done.

To get my own CVS, I downloaded the CVS server and client for Windows. Installed the server first, a bit of configuration, then install the client. Now, I’m using WinCVS as my CVS GUI client. You can do without a GUI but for a newbie such as myself, I guess it’s better to start off with a GUI client. Quite tough at first. Lots of options, buttons and I have no clue where to start with. But after an hour, I managed to figure things out a bit and had my first try at committing changes to the repository.

The repository, located on the server, is where all the files that you want version-controlled goes to. After setting up the server connection settings, logging in, I did an “Import Module” on the folder containing files that I want to have in the CVS. A tick appears on the folder which I assume, means it’s marked for CVS. Then I tried editing the files. Configured WinCVS to launch my favourite crimsoneditor for file editing. Added a few lines, saved, the file appeared red in WinCVS which means it was modified.

Right clicking on the file, we are presented with many options but I will only talk about the first 2, “Update Selection”, “Commit Selection”. I assume Update means to update your local copy with the latest copy on the CVS server. Commit, as I have tried, updates changes you made, to the server. The version number of the file, gets incremented each time I commit changes. You can include a comment when you commit a change, this helps you and other developers to know what has been changed.

There are other features that I have no idea, how it works, but I’m going to take this slow and steady. The above is just my experience with CVS today. There may be errors somewhere, so do feel free to point it out by posting a comment. [:)]

CVS Server -> CVSNT
CVS Client -> WinCVS
CVS Server Installation guide
CVS Manual -> HTML Cederqvist for CVS
Some good links for beginning CVS

PHP: Changing text in hundreds of files

Been a while since I wrote a tech entry. And this will be my first one,
involving PHP coding. [X)]

At work, I’m given the responsibility to manage a group of websites. The
codes are given to us by our counterparts, and we are running the sites under a
different domain name. There’s about 15 of them, each filled with 20-30 pages
and most have a few hundred lines of code. My task is to edit some links and
upload them to our webhosting server.

I soon got bored updating each single with the search feature in CrimsonEditor. So I took
this opportunity to write a script to automatically search and
destroy replace each occuring text with another.

To begin with, I planned and came up with the following pseudocode.

Define text to search;
Define text to replace;

Loop
through the directories and their sub-directories
  if file extension is
of htm, html, phtml
    read file
contents;
    search and replace;
   
save file and close;
  end if
end loop

I got a directory looping code from the online manual at PHP, submitted by
another person. The text to search and replace are submitted through a form, and
security won’t be important since I’m running it on my own development machine,
not on the public webhost.

This is the form that contains the array of search and replace text. To have
the values automagically created as an array to access, you add square brackets
at the end of the form input names.

<form method=”post”
action=”updater.php”>
 <table border=”0″ cellspacing=”0″
cellpadding=”2″ width=”900″>
  <tr><th>Replace
this</th><th>With
this</th></tr>
  <tr>
   <td><input
type=”text” name=”search[]”
value=”www.hotels-direct-paris.com”></td>
   <td><input
type=”text” name=”replace[]”
value=”paris-hotels.bestavailablerates.com”></td>
  </tr>
  <tr>
   <td><input
type=”text” name=”search[]”
value=”www.hotels-direct-venice.com”></td>
   <td><input
type=”text” name=”replace[]”
value=”venice-hotels.bestavailablerates.com”></td>
  </tr>
  <tr>
   <td><input
type=”text” name=”search[]”
value=”www.hotels-direct-spain.com”></td>
   <td><input
type=”text” name=”replace[]”
value=”spain-hotels.bestavailablerates.com”></td>
  </tr>
 </table>
 <div
align=”center”><input type=”submit” name=”updaterSubmit”
value=”Update”></div>
</form>

Here’s the PHP Code that gets triggered when the form is submitted. It calls
the update function and runs the code on the directory I hardcoded. Always make
backup copies! [:)]

<?php
 if (isset($_POST[‘updaterSubmit’]) &&
$_POST[‘updaterSubmit’]==’Update’)
{
  update(‘C:\Inetpub\wwwroot\BARwebsites\testcopies\\’);
 }
?>

And the update() recursive-function that loops through the directories,
replacing text

function update($curpath) {
 $dir =
dir($curpath);
 echo
“<b>$curpath</b><blockquote>”;
 while ($file =
$dir->read()) {
  if($file != ‘.’ && $file != ‘..’)
{
   if (is_dir($curpath.$file))
{
    update($curpath.$file.’\\’);
   }
else {
    if (strpos($file,’.htm’) ||
strpos($file,’.html’) || strpos($file,’.phtml’))
{
     echo $file.'<br />’; // display
filename
     $result =
str_replace($_POST[‘search’], $_POST[‘replace’],
file_get_contents($curpath.$file));
     $filepointer
= fopen($curpath.$file,’w+’); // opens
file
     fwrite($filepointer, $result); // truncate
file, write content
     fclose($filepointer); //
close
file
    }
   }
  }
 }
 $dir->close();
 echo
‘</blockquote>’;
 flush();
 return;
}

This line is where the interesting part comes. Click on the function names to
read up on them. Note that $_POST[‘search’] and $_POST[‘replace’] are globally
accessible, array variables.

$result = str_replace($_POST[‘search’],
$_POST[‘replace’], file_get_contents($curpath.$file));

Might look poorly coded to some, but I only want to accomplish my aim in a
short time without spending too much time on writing complex error-handling codes before they are passed in. I do welcome any positive/negative comments/advice to
help me improve my PHP skills. [:D]

I am bandwidth hungry

There is never enough! But then, since I don’t shut off my computers, I have all the time in the world to finish my downloads slowly over a 512kbps ADSL connection. All I ask for is more upload speed so my webserver can serve pages faster and I don’t have to frustrate myself with webhosting providers. I’m currently serving anime files on IRC, capped at 15KB/s, leaving me about 10-15KB/s for gaming and forcing this paragraph down to your internet browser.


If I could save up enough money, I’ll be getting a 80GB harddisk with 8MB cache, and start using my Athlon 1GHz CPU to run this site and some others. Currently, this blog and my ircquotes site is being processed on a Pentium 2 233MHz. The other PC that’s sitting on the left of my main rig in the photos of my room I posted a few entries ago.


Back to the topic, I came across 2 infuriating links regarding SingTel’s use of P-cube to throttle down the downloads of SingNet’s ADSL subscribers and one of them unfortunate ones happens to be me. The Internet Bandwidth forum at HardWareZone’s forums are heating up with a few discussions of SingTel’s use of P-cube.


Here’s the stuff and I’m highlighting the important points to note…


http://www.nwfusion.com/edge/columnists/2003/0707bleed.html

During the last year they have had many subscriber complaints as to unsatisfactory bandwidth and performance, and many customers have churned. They had to add many costly leased lines to their infrastructure, and have seen international transit traffic soar. Through the use of P-Cube’s product they found that 60% of their traffic was P2P. Additionally, they found that only 5% of the users accounted for 70% of the P2P traffic.
I belong to that 5% so satisfy me cos I paid you!

SingTel also implemented new services to help control this problem. They limited P2P traffic from international transit links. By using regional bandwidth links, internal costs were reduced. They allowed for unlimited P2P during off-peak hours, but limited during peak.
And by peak, you mean the only period of time where I am home from work and play FinalFantasy 11 with lag because of limited bandwidth.

http://www.isp-planet.com/news/2003/p-cube_030707.html

We spoke to one satisfied P-Cube customer, Benny Chee, senior network engineer at SingTel, Singapore’s ILEC.
You’re satisfied because you’re probably getting a raise for reducing our bandwidth.

Chee says he only needs to throttle P2P during the peak usage hours. During peak hours, P2P traffic is generally throttled to one-fifth normal speed. “We want to maintain 512 Kbps all the way to the desktop.”
How the heck do you maintain that speed when you are throttling our traffic to one-fifth the normal?

The company might also like to charge more for heavy usage, but it has to maintain its current low price because Starhub offers 1.5 Mbps for about $32 (56 Singapore Dollars).
Bravo Starhub, Bravo!!

My question, how damn hard is it to improve Singapore’s internet bandwidth? I’ve seen advertisements of SingNet’s boasting high speeds at low costs but open your fucking eyes and look at yourself. Limiting our download speeds simply contradicts what you have been promoting since the dawn of ADSL, dedicated bandwidth.

Hardware problems go away, come again another day.

Headaches from lack of sleep. Aching shoulders from work, possible bad sitting posture. Internet Service Provider giving massive frustrations.


Apart from that, I have a few problems as well with the new computer. Not major though. As long as Final Fantasy 11 runs smooth, my anime videos play well and my cdwriter burns with passion, I’m a happy man.


In 2 months, if Singnet does not improve, I will make a switch over to Qala. In HardWareZone’s forums, it is reported that Singnet has acquired hardware that is capable of detecting what sort of data is flowing, e.g. data flowing between bittorrent programs, and then impose a speed cap on it. The device in question is P-cube, http://www.p-cube.com/index.shtml. A lot of other Singnet users are complaining about slow download speeds. As slow as 1KB/s on highly seeded bittorrents.


Singnet has reported huge profits. And those stingy people, instead of investing money on more bandwidth, chose to invest money to frustrate their subscribers.


And finally, this article says Microsoft may have found a way to render harddisks useless, and they intend to implement this into ServicePack 2 and ruin computers with illegal cd keys. Well, if poor people cannot afford to buy their expensive OS, what difference is there when they use illegal copies?

Got that AMD Athlon64 3200+!!

Wheeeeee…


8.30pm-1am: Fixing up the hardware.


1-1.40am: Troubleshooting floppy drive, turned out the new floppy cable was faulty. Troubleshooting RAID installation. Turned out the floppy disk that came with the motherboard was buggy.


1.40-2.30am: Tried sleeping but can’t. Then idea struck me to copy the driver files from the CD into the floppy.


2.30-4.30am: Installing the rest of my harddisk drives, update Windows, installing usual software and configuring Windows settings. You can only have the 2 SATA Raid 0 disks connected if you want to install an operating system on that Raid 0 array.


4.30-7am: Sleeeeeep…


7-7.40am: Before I left for work, I tried playing Lineage2, using a friend’s game account, on the North American servers. It was wonderful. Finally am I able to experience smooth, high quality gaming. There’s still some choppiness in some areas but I have yet to install DirectX 9.0b so that could be the cause.


I managed to buy a CG stepping, ClawHammer core version of the Athlon64. CG stepping, from what I know, means better overclocking results and performance. ClawHammer means it’s the one with 2GHz core speed, 1024KB L2 cache. The other NewCastle core has 2.2GHz core speed but only 512KB L2 cache.


2 sticks of PC3200 CAS2.5 Corsair 512MB rams.


2 Western Digital 10,000RPM, 8MB cache, 36GB Raptor harddisks Stripe Raided. It simply means combining both harddisks into one, double the storage, double the read/write speeds of 1 Raptor. Because of this, WindowsXP Professional installed in only 10 minutes.