views:

33

answers:

2

I am thinking about converting a visual basic application (that takes pipe delimited files and imports them into a microsoft sql database) into a php page. One of these files is on average about 9 megabytes in size. (I couldn't be accurate about the number of lines involved but I'd say it's about 20 thousand)

One of the advantages being that any changes made to the page would be automatically 'deployed' to the intended user (currently when I make changes to the visual basic app, which was originally created by someone else, I have to put the latest version on all the PCs of the people that use it).

Problem is these imports can take like two minutes to complete. Two minutes is a long time in website-time so I would like to provide feedback to the user to indicate that the page hasn't failed/timed out and is definitely doing something.

The best idea that I can think of so far is to use ajax to do it incrementally. Say import 1000 records at a time then feed back, implement the next 1000, feed back, and so on.

Are there better ways of doing this sort of thing that wouldn't require me to learn new programming languages or download apps or libraries?

+1  A: 

How are you importing the data into the database? Ideally, you should be using SQL Server's BULK INSERT which likely would speed up things. But it's still a matter of uploading the file for parsing...

I don't think it's worth the effort to get status of insertions - most sites only display an animated gif/etc (like the hourglass, etc) to indicate that the system is processing things but no real details.

OMG Ponies
Is this the same kind of "comment as answer" I just got beat up over?
TML
OMG Ponies
Just trying to understand what's what here, because the question seemed to be "how do I provide feedback", and your response seemed to be "I don't think it's worth doing", figured it'd be a good idea to ask someone with a 44k score to clarify how that's an answer to the question as asked.
TML
I thought it was an ok answer and have accepted it.The original code in the VB app didn't use the bulk insert (surprising since the authors were supposed to be SQL experts and developers) and I didn't think about it, but I will certainly give it a try.
MrVimes
+2  A: 

You don't have to make the Visual Basic -> PHP switch. You can stick with VB syntax in ASP or ASP.NET applications. With an ASP based solution, you can reuse plenty of the existing code so it won't be learning a new language / starting from scratch.

As for how to present a long running process to the user, you're looking for "Asynchronous Handlers" - the basic premise being the user visits a web page (A) which starts the process page (B).

  • (A) initiates (B), reports starting to the user and sets the page to reload in n seconds.
  • (B) does all the heavy lifting - just like your existing VB app. Progress is stored in some shared space (a flat file, a database, a memory cache, etc)
  • Upon reload, (A) reports current progress of (B) by read-only accessing the shared space (B) is keeping progress in.

Scope of (A):

  • Look for running (B) process - report status if found, or initiate fresh (B) process. Since (B) appears to be based on the existence of files (from your description) you might grant (A) the ability to determine if there's any point in calling (B) or not (ie. If files exist call (B) else report: nothing to do) or you may wish to keep the scopes entirely free and call (B).
  • Report progress of (B).
  • Should take very little time to execute, may want to include HTTP refresh header so user automatically gets updates.

Scope of (B):

  • Same as existing VB script – look for files, load… yada yada yada.
  • Should take similar time to execute as existing VB script (2 minutes)

Potential Improvements:

  • (A) could use an AJAX interface, so instead of a page-reload (HTTP refresh), an AJAX call is made every n seconds and simply the status box is updated. Some sort of animated icon (swirling wheel) will give the user the impression something is going on between refreshes.
  • It sounds like (B) could benefit from a multi-threaded approach (loading multiple files at once) depending on whether the files are related. As pointed out by Ponies, there may be a better strategy to such a load, but that's a different topic all together :)
  • Some sort of semaphore/flag approach may be required if page (A) could be simultaneously hit at the same time by multiple users and (B) takes a few seconds to start up and report status'.

Both (A) and (B) can be developed in PHP or ASP technology.

Rudu
Guided by your reply I have implemented as follows...First loaded page has form to upload file. Submits form in normal way (no ajax)...Submitted page (A) creates a permanent copy of the file and then calls an ajax page (B), passing the filename...Ajax page (B) performs the database update from the file...Meanwhile Page (A) runs a third page (C) every second which simply does a database call (select count(*) from the_table)...When page B completes, page A stops running page C and reports the final record count. All the 'pages' are actually just one page with different modes.
MrVimes
Sounds solid. The only other thing you might need to worry about - what happens if the user closes their browser or hits refresh on page A during the B/C cycle? Does B complete, restart, or fail? It may never come up, but you really don't need duplicate data, or an incomplete load as a result of an overzealous user.
Rudu