Index: trunk/dbconfig/pstamp.md
===================================================================
--- trunk/dbconfig/pstamp.md	(revision 28105)
+++ trunk/dbconfig/pstamp.md	(revision 28106)
@@ -59,2 +59,6 @@
     fault       S16         0
 END
+
+pstampWebRequest METADATA
+    num         S64         0    # Primary Key AUTO_INCREMENT
+END
Index: trunk/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- trunk/ippTools/share/pxadmin_create_tables.sql	(revision 28105)
+++ trunk/ippTools/share/pxadmin_create_tables.sql	(revision 28106)
@@ -1401,4 +1401,9 @@
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
+CREATE TABLE pstampWebRequest (
+        num BIGINT AUTO_INCREMENT,
+        PRIMARY KEY(num)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
 CREATE TABLE distTarget (
     target_id   BIGINT AUTO_INCREMENT,
Index: trunk/ippTools/src/pstamptool.c
===================================================================
--- trunk/ippTools/src/pstamptool.c	(revision 28105)
+++ trunk/ippTools/src/pstamptool.c	(revision 28106)
@@ -53,4 +53,5 @@
 static bool updatedependentMode(pxConfig *config);
 static bool revertdependentMode(pxConfig *config);
+static bool getwebrequestnumMode(pxConfig *config);
 
 # define MODECASE(caseName, func) \
@@ -95,4 +96,5 @@
         MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode);
         MODECASE(PSTAMPTOOL_MODE_REVERTDEPENDENT, revertdependentMode);
+        MODECASE(PSTAMPTOOL_MODE_GETWEBREQUESTNUM, getwebrequestnumMode);
         default:
             psAbort("invalid option (this should not happen)");
@@ -1334,2 +1336,18 @@
     return true;
 }
+
+static bool getwebrequestnumMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    if (!pstampWebRequestInsert(config->dbh, 0 )) {
+        psError(PS_ERR_UNKNOWN, false, "failed to insert pstampWebRequest");
+        return false;
+    }
+
+    psS64 req_id = psDBLastInsertID(config->dbh);
+
+    printf("%" PRId64 "\n", req_id);
+
+    return true;
+}
Index: trunk/ippTools/src/pstamptool.h
===================================================================
--- trunk/ippTools/src/pstamptool.h	(revision 28105)
+++ trunk/ippTools/src/pstamptool.h	(revision 28106)
@@ -48,4 +48,5 @@
     PSTAMPTOOL_MODE_UPDATEDEPENDENT,
     PSTAMPTOOL_MODE_REVERTDEPENDENT,
+    PSTAMPTOOL_MODE_GETWEBREQUESTNUM,
 } pstamptoolMode;
 
Index: trunk/ippTools/src/pstamptoolConfig.c
===================================================================
--- trunk/ippTools/src/pstamptoolConfig.c	(revision 28105)
+++ trunk/ippTools/src/pstamptoolConfig.c	(revision 28106)
@@ -235,4 +235,7 @@
     psMetadataAddBool(projectArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
 
+    // -getwebrequestnum
+    psMetadata *getwebrequestnumArgs = psMetadataAlloc();
+
     psMetadata *argSets = psMetadataAlloc();
     psMetadata *modes = psMetadataAlloc();
@@ -264,4 +267,5 @@
     PXOPT_ADD_MODE("-modproject",      "", PSTAMPTOOL_MODE_MODPROJECT, modprojectArgs);
     PXOPT_ADD_MODE("-project",         "", PSTAMPTOOL_MODE_PROJECT,    projectArgs);
+    PXOPT_ADD_MODE("-getwebrequestnum","", PSTAMPTOOL_MODE_GETWEBREQUESTNUM,   getwebrequestnumArgs);
 
     if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
Index: trunk/pstamp/scripts/pstamp_insert_request.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_insert_request.pl	(revision 28105)
+++ trunk/pstamp/scripts/pstamp_insert_request.pl	(revision 28106)
@@ -114,31 +114,25 @@
 
 exit 0;
-
-# Temporary hack
-# webrequest number is stored in a file in the current directory
-#
-# get this number from the database
+# Ask the database for the next web request number
 sub get_webreq_num
 {
-    my $filename = "$workdir/webreq_num.txt";
-    if (! open IN, "+< $filename" ) {
-        my $initial_num = 1;
-        open IN, "> $filename" or die "can't open $filename";
-        print IN "$initial_num\n" or die "failed to initialize $filename";
-        close IN;
-        return $initial_num;
+    my $command = "$pstamptool -getwebrequestnum";
+    $command .= " -dbname $dbname" if $dbname;
+    $command .= " -dbserver $dbserver" if $dbserver;
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        print STDERR @$stderr_buf;
+        die("Unable to perform pstamptool -getwebrequestnum: $error_code");
+    }
+    my $webreq_num = ${$stdout_buf}[0];
+    chomp $webreq_num;
+
+    if (!$webreq_num) {
+        die("pstamptool -getwebreqnum returned no value");
     }
 
-    my $webreq_num = <IN>;
-    chomp $webreq_num;
+    # print STDERR "webreq_num $webreq_num\n";
 
-    print STDERR "$webreq_num\n" if $verbose;
-
-    my $next = $webreq_num + 1;
-    truncate IN, 0;
-    seek IN, 0, 0;
-    print IN "$next\n";
-
-    close IN;
     return $webreq_num;
 }
Index: trunk/pstamp/scripts/pstamp_webrequest.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_webrequest.pl	(revision 28105)
+++ trunk/pstamp/scripts/pstamp_webrequest.pl	(revision 28106)
@@ -23,5 +23,5 @@
 
 my $host = hostname();
-my $verbose = 0;
+my $verbose = 1;
 my $dbname;
 my $dbserver;
@@ -152,29 +152,25 @@
 exit 0;
 
-# Temporary hack
-# webrequest number is stored in a file in the current directory
-#
+# Ask the database for the next web request number
 sub get_webreq_num
 {
-    my $filename = "webreq_num.txt";
-    if (! open IN, "+< $filename" ) {
-        my $initial_num = 1;
-        open IN, "> $filename" or die "can't open $filename";
-        print IN "$initial_num\n" or die "failed to initialize $filename";
-        close IN;
-        return $initial_num;
+    my $command = "$pstamptool -getwebrequestnum";
+    $command .= " -dbname $dbname" if $dbname;
+    $command .= " -dbserver $dbserver" if $dbserver;
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        print STDERR @$stderr_buf;
+        die("Unable to perform pstamptool -getwebrequestnum: $error_code");
+    }
+    my $webreq_num = ${$stdout_buf}[0];
+    chomp $webreq_num;
+
+    if (!$webreq_num) {
+        die("pstamptool -getwebreqnum returned no value");
     }
 
-    my $webreq_num = <IN>;
-    chomp $webreq_num;
+    # print STDERR "webreq_num $webreq_num\n";
 
-    print STDERR "$webreq_num\n" if $verbose;
-
-    my $next = $webreq_num + 1;
-    truncate IN, 0;
-    seek IN, 0, 0;
-    print IN "$next\n";
-
-    close IN;
     return $webreq_num;
 }
