Thank you. I added that but still get GPFs at odd times on the same line: curl_global_cleanup(). Here is my code:
METHOD SendOtherTxts() CLASS TService
Local oQ := TAdsQuery():New() //ADS Sql class
Local oQ2 := TAdsQuery():New()
Local Line, hCurl, nError, cResponse, httpcode, cPostFields, cTel, aData
oQ2:cSql:= "UPDATE SMSMessages SET DTSent = now() WHERE celnumber = '$1$'\n"
oQ:cSql := "SELECT celnumber, text FROM SMSMessages WHERE DTSent IS NULL \n"
oQ:Run()
if oQ:nRows > 0 //messages in queue pending to be sent
LogData( ::cLogFile, { "Sending other texts from SMSMessages table:", oQ:nRows }, ::nMaxLogSize )
curl_global_init()
if !empty( hCurl := curl_easy_init() )
FOR EACH LINE IN oQ:aResultSet
cTel := OnlyDigits( Line[ 1 ] )
cPostFields := 'To=' + '1' + cTel +; //1 prefix for US numbers
'&From=' + TEL_FROM +;
'&Body=' + Line[ 2 ] //text message to be sent
LogData( ::cLogFile, { cPostFields }, ::nMaxLogSize )
curl_easy_setopt( hCurl, HB_CURLOPT_POST, 1 )
curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD, ACCOUNT_SID + ':' + AUTH_TOKEN )
curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
curl_easy_setopt( hcurl, HB_CURLOPT_POSTFIELDS, cPostFields )
nError := curl_easy_perform( hCurl )
curl_easy_getinfo( hCurl, HB_CURLINFO_RESPONSE_CODE, @httpcode )
IF nError = HB_CURLE_OK
cResponse = curl_easy_dl_buff_get( hCurl )
IF ! empty( cResponse )
oQ2:aSubstitutes := { Line[ 1 ] } //Telephnoe number where SMS is to be sent
oQ2:Run() //updates SMSMessages table record with timestamp
hb_jsonDecode( cResponse, @aData )
//TODO find if message was queued by checking "Status:" returned in cResponse JSON
LogData( ::cLogfile, aData, ::nMaxLogSize )
ENDIF
ELSE
LogData( ::cLogFile, { "Error Sending Other SMS Texts. Details below:" }, ::nMaxLogSize )
LogData( ::cLogFile, Line, ::nMaxLogSize ) //Write current query record to logfile
LogData( ::cLogFile, { "Error Num:", nError, "Httpcode:", httpcode }, ::nMaxLogSize )
LogData( ::cLogFile, curl_easy_strerror( nError ) )
ENDIF
curl_easy_reset( hCurl )
NEXT //next appointment in table
curl_easy_cleanup( hCurl )
hCurl := Nil
hb_gcAll( .t. )
endif
curl_global_cleanup() //GPF happens here at odd moments. Not every time.
endif
oQ2:End()
oQ:End()
RETURN NIL