Always Get Better

Archive for the ‘PHP’ Category

Wamp Server Crashes Installing X-Cart

Sunday, January 24th, 2010

When running a default installation, WAMP Server’s Apache crashes when installing X-Cart. The error happens immediately after setting up the MySQL tables and is caused by the curl extension in PHP.

To resolve, click on the WAMP Server icon in the task tray, go to Apache -> Version -> Get More. Download one of the 2.0 series Apache servers and install it.

Repeat the process for PHP; download one of the 5.0 series PHP versions and install it.

Switch WAMP Server to the new versions and run the install again – it should work with no problems.

  • Share/Bookmark

“Connection to Server Reset” when Installing Drupal

Friday, May 2nd, 2008

Has anyone else had this issue?

When I try to install Drupal on a Windows 2003 Apache server, I get a pause and then “Connection Reset” error under Firefox.  If I then try to install it using Internet Explorer, the installation process comes up immediately and works without a hitch.

I still can’t seem to get the admin ‘Modules’ page to load at all – PHP is crashing.  That is an entirely separate issue as far as I can tell.

  • Share/Bookmark

Apache: Enabling mod_rewrite on Windows 2003 Server

Monday, April 21st, 2008

Recently I had to set up a Wordpress blog on a Windows 2003 server, which involved installing Apache, PHP and MySQL.  Everything went pretty well – except for the typical PHP.ini problems I shall write about later.

Once the database was set up and I had the blog running, I tried to adjust the permalink structure using .htaccess rewrite rules so they would be more human-readable.

Out of the box, mod_rewrite isn’t enabled on Windows Apache.

The steps I took to resolve the problem were:

  1. Uncomment the line containing ‘LoadModule mod_rewrite modules/mod_rewrite.so
  2. In the VirtualHost directive hosting the blog, add ‘AllowOveride All
  3. Restart Apache

It works like a charm, now.  All the tools ship with Apache, it’s just a matter of configuring them as needed.

  • Share/Bookmark

Maintaining SQL Connections in ASP.NET

Monday, February 11th, 2008

There is a lot of conflicting advice with regard to the proper way of using SQL connections in web work.  The two main schools of thought are:

 

  1. Open a connection once, use it for everything and free it when the page request is complete.
  2. Open a connection only when it is needed, then fre it right away.

 

It All Comes Down to Speed

Any operation performed by the server has a cost associated with it.  Loops and counts happen on the CPU and are incredibly fast.  Caches are stores in system memory and seem fast but are in fact thousands of times slower than direct CPU operation.

 

As far as internal server access goes, reading and writing to the hard drive is representative of the most expensive operation performed by applications.  If possible, memory is oftent he best storage medium for program instructions.

 

Consider Database Access Costs

Databases live in a realm somewhere between hard drives and memory.  A good DBMS reacts to requests by storing execution plans and data in system memory thereby reducing the amount of time applications have to wait for information to load off the hard drive.

 

In terms of execution costs, connecting to the database is up there with reading from the hard drive.  Is a database connetion isn’t needed, don’t create one.

 

Which is better?

Considering the high price of connecting to a database, which of the following makes the most sense for our web application?

 

  1. Creating the connection to the database, performing all operations, and closing the connection after the is complete, org;
  2. For every request, creating a connection, executing a query, then closing the connection.  Repeat every time a new piece of information is required.

 

In classic ASP’s ADO, #1 was the best option.  In modern ASP.NET’s ADO.NET, #2 is the way to go.  That was a trick question.

 

Classic ASP – ADO

Using classic ASP, the developer has a great deal of control over the sequence in which their code will run.

 

It’s very easy to open a single connection at the top of a web page and use it for all of that page’s database operations.  At the end of the page, the developer writes code logic to free all record sets used, close memory objects, and release the connection.

 

ADO.NET

When writing code for ASP.NET, we strive to be “good” .NET citizens.  We are given a lot of power to write application logic never before possible on the web, and we are asked to relinquish some of our finer-grained control over resources.

 

Generally, managed resources benefits the programmer by freeing them to focus more on the business requirements of their project rather than their specific environment’s implementation.  Database connectivity, however, is a concept that has to be updated to fit the .NET paradigm.

 

Whereas before we controlled when database resources were released to the system, now the garbage collector has taken responsibility for the task.  If we open a database connection when the page request begins, we have no real guarantee it will be released in a timely manner when the page request completes.

 

This means the only way to prevent the server from running out of connections is by creating, using, and immediately freeing them every time we want to retrieve information from the database.

 

What about the cost of execution?  One would assume we’ve taken two steps back but ASP.NET introduces connection pooling for this situation.

 

Connection Pooling is your friend

Any time a connection is requested, the server looks to a special pool of memory objects where it keeps previously used database connections.  If there are any connections no longer being used, the server will return those unused connections before creating a new one.

 

Essentially the server only incurs the cost of creating a connection the first time it is used, or whenever demand for a particular application spikes.

 

When our program is done with the database, it releases the connection back into the pool for other requests.

 

Never Create Global Connection Objects

The morale of the story is: work with the .NET framework and let it do its job.  As long as we are willing to let go of old ways of thinking and adapt to the new technologies, our programming lives will become ever simpler.

 

Every day web applications grow in their complexity.  Fortunately the power and capabilities of the tools we have available also continue to improve.

 

Expect databases to continue driving bigger and better web presences.  The more skilled we become at working with them the more likely we are to succeed in creating stable, reliable and scalable applications to take advantage of them.

  • Share/Bookmark

SEO Powered by Platinum SEO from Techblissonline