Hi there,
I am very new to trapping errors in PHP.
I have an application that has a fixed number of licenses for clients to connect.
One of my PHP scripts consumes a license.
Basically I want the script to attempt the connection and if it fails due to no available licenses to sleep for 30 seconds then try the connection again before proceeding with the rest of the script.
The script I am trying to rewrite in PHP is this Python script.
I just can't get my head around getting the script to retry the connection on failure.
Peter.
Remember- It's nice to be important,
but it's important to be nice
I am very new to trapping errors in PHP.
I have an application that has a fixed number of licenses for clients to connect.
One of my PHP scripts consumes a license.
Basically I want the script to attempt the connection and if it fails due to no available licenses to sleep for 30 seconds then try the connection again before proceeding with the rest of the script.
The script I am trying to rewrite in PHP is this Python script.
Code:
while True:
try:
cnxn = pyodbc.connect('DRIVER={D3 ODBC Driver};SERVER=192.168.1.1;PORTNUMBER=1603;VIRTUALMACHINE=192.168.1.1;UID=xx;PWD=;ACCOUNT=xx;ACPASSWORD=;ConnectDialog=No;AConnectDialog=No;D3VERSION=710;D3PWD=;NotNullConstraint=Yes;LoginTimeout=20;')
cursor = cnxn.cursor()
cursor.execute("SELECT IVMST.RSV_DESC, IVMST.AVG_COST, IVMST.COST, IVMST.INV, IVMST.MU1, IVMST.MU2, IVMST.MU3, IVMST.N_12MON, IVMST.SALE, IVMST.VENDOR, IVMST.RSV_GROUP, IVMST.IVMST_id, IVMST.BRAND, IVMST.RETAIL, IVMST.SUPNAME, IVMST.S1INV, IVMST.S2INV FROM IVMST IVMST")
mcursor.execute("DELETE FROM d3_import")
mconn.commit()
for row in cursor:
c = 0
mcursor.execute("""INSERT INTO d3_import VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE rsv_desc=%s, avg_cost=%s, cost=%s, inv=%s, mu1=%s, mu2=%s, mu3=%s, n_12mon=%s, sale=%s, vendor=%s, rsv_group=%s, brand=%s, retail=%s, supname=%s, s1inv=%s, s2inv=%s""", (row[11], row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[12], row[13], row[14], row[15], row[16], row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[12], row[13], row[14], row[15], row[16]))
mconn.commit()
c = 0
for v in row:
if row[c] == None:
row[c] = ""
c += 1
f.write(str(row[11]) + "," + str(row[0]) + "," + str(row[1]) + "," + str(row[2]) + "," + str(row[3]) + "," + str(row[4]) + "," + str(row[5]) + "," + str(row[6]) + "," + str(row[7]) + "," + str(row[8]) + "," + str(row[9]) + "," + str(row[10]) + "," + str(row[11]) + "," + str(row[14]) + "," + str(row[15]) + "," + str(row[16]) + "\n")
break
except:
print "Connection failed, probably too many licenses used. Trying again in 5 seconds..."
time.sleep(5)
I just can't get my head around getting the script to retry the connection on failure.
Peter.
Remember- It's nice to be important,
but it's important to be nice