FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index mod_harbour Migration to the new mod_harbour fastCGI
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Migration to the new mod_harbour fastCGI
Posted: Wed Jul 22, 2020 08:11 AM

Thanks a lot my friend.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Migration to the new mod_harbour fastCGI
Posted: Thu Jul 23, 2020 09:08 AM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Migration to the new mod_harbour fastCGI
Posted: Sat Jul 25, 2020 08:11 AM
Hi Antonio.
I've installed the new mod-harbour fcgi but I have an error.
The compiled prg seem not loaded.

This is the main.prg made for testing:
Code (fw): Select all Collapse
// {% LoadHRB( "retedb.hrb" ) %}

memvar hForm

**************************************************************************
Function main()

local mv_username:="" , mv_password:="" , nErr:=0 , zMail:="" , cUserName:=""
local link_intra:=""  , pagina_arrivo:="" , controllo_web:=""
local cookie_stringa

Setting_db()

SetCookie( 'blu1', "cookie numero 1" + "|" + "2020|1|1|", 90000, '' )
SetCookie( 'blu2', "cookie numero 2" + "|" + "2020|2|2|", 90000, '' )
SetCookie( 'blu3', "cookie numero 3" + "|" + "2020|3|3|", 90000, '' )
SetCookie( 'blu4', "cookie numero 4" + "|" + "2020|4|4|", 90000, '' )
SetCookie( 'blu5', "cookie numero 5" + "|" + "2020|5|5|", 90000, '' )
SetCookie( 'blu6', "cookie numero 6" + "|" + "2020|6|6|", 90000, '' )
SetCookie( 'blu7', "cookie numero 7" + "|" + "2020|7|7|", 90000, '' )
SetCookie( 'blu8', "cookie numero 8" + "|" + "2020|8|8|", 90000, '' )

Return nil

**************************************************************************
function msgAlert( cMsg )
?  "<script>alert('"+cMsg+"');</script>"
Return nil


The retedb.prg contains 2 functions :

Code (fw): Select all Collapse
**************************************************************************

Function BLR(wait)   // BLOCCA IL RECORD

** wait = i secondi di attesa dopodiche' la funzione ritorna .F.
**        se non riesce ad aprire il file

local forever

IF RLOCK()
   Return .T.
ENDIF

forever=(wait=0)

Do while ( forever .or. wait > 0 )
   SecondsSleep(1)
   wait-=0.50
   IF RLOCK()
      Return .T.
   ENDIF
   IF INT(wait) = wait
      EXIT
   ENDIF
Enddo

Return .F.

**************************************************************************

Function Setting_db()

REQUEST HB_LANG_IT
HB_LANGSELECT("IT")
REQUEST DBFCDX
REQUEST DBFFPT
REQUEST ADS
RddRegister( "ADS", 1 )
RddSetDefault("ADS")
SET SERVER REMOTE
SET FILETYPE TO ADT
SET(_SET_AUTORDER,1)
SET AUTOPEN ON
set(_SET_OPTIMIZE,.T.)
ADSLOCKING(.T.)

SET DATE BRITISH
SET DELETED ON
SET CENTURY ON

Return nil


But the I try to run the main.prg I have this error :

Code (fw): Select all Collapse
Error: Undefined function
operation: SETTING_DB
called from: pcode.hrb, SETTING_DB, line: 0
called from: pcode.hrb, MAIN, line: 12
called from: HB_HRBDO, line: 0
called from: ..\source\exec.prg, EXECUTE, line: 70

Source:
0010: local cookie_stringa
0011:
0012 =>Setting_db()
0013:
0014: SetCookie( "blu1", "cookie numero 1" + "|" + "2020|1|1|", 90000, "" )


With the previous mod-harbour the program runs without problems.
What could be wrong ?
Thanks a lot.
Massimo
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Migration to the new mod_harbour fastCGI
Posted: Sat Jul 25, 2020 06:39 PM

Massimo,

Please have all the source code in one single PRG file.

Try it without HRB files (for now)

many thanks for your feedback

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Migration to the new mod_harbour fastCGI
Posted: Sun Jul 26, 2020 11:16 AM

Antonio,
tested with everything inside one prg without HRB and it's working.
But I cannot convert a big procedure in FastCGI that is made of several prg and 4 HRB files.
I wait for your future suggestions.
Thanks a lot.
Massimo

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Migration to the new mod_harbour fastCGI
Posted: Sun Jul 26, 2020 12:24 PM
Massimo,

Please use this function MyLoadHRB() and change the value 1 (twice in the code) from 1 up to 4 and check
if with some of those values it works as expected, many thanks

Code (fw): Select all Collapse
function MyLoadHRB( cHrbFile_or_oHRB )

   local lResult := .F.

   if ValType( cHrbFile_or_oHRB ) == "C"
      if File( hb_GetEnv( "PRGPATH" ) + "/" + cHrbFile_or_oHRB )
         AAdd( M->getList,;
            hb_HrbLoad( 1, hb_GetEnv( "PRGPATH" ) + "/" + cHrbFile_or_oHRB ) )
         lResult = .T.   
      endif      
   endif
   
   if ValType( cHrbFile_or_oHRB ) == "P"
      AAdd( M->getList, hb_HrbLoad( 1, cHrbFile_or_oHRB ) )
      lResult = .T.
   endif
   
return lResult
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Migration to the new mod_harbour fastCGI
Posted: Sun Jul 26, 2020 05:18 PM
Hi Antonio.
I put your function at the end of the prg and wrote this line at the beginning :

Code (fw): Select all Collapse
// {% MyLoadHRB( "retedb.hrb" ) %}


But when I run the prg I receive this error :

Code (fw): Select all Collapse
Error: Undefined function
operation: MYLOADHRB
[ 1] = C retedb.hrb
called from: pcode.hrb, MYLOADHRB, line: 0
called from: ..\source\exec.prg, (b)REPLACEBLOCKS, line: 143
called from: ..\source\exec.prg, REPLACEBLOCKS, line: 143
called from: ..\source\exec.prg, EXECUTE, line: 63

Source:
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Migration to the new mod_harbour fastCGI
Posted: Sun Jul 26, 2020 06:29 PM
Massimo,

Please download modharbour.exe from here:
https://github.com/FiveTechSoft/mod_harbour/blob/master/fastcgi/windows/win64/ADS/modharbour.exe

And try to use LoadHRB() as usual

many thanks for your very valuable feedback
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Migration to the new mod_harbour fastCGI
Posted: Mon Jul 27, 2020 07:23 AM
Antonio,
this is the hrb file
Code (fw): Select all Collapse
Function Setting_db()

REQUEST HB_LANG_IT
HB_LANGSELECT("IT")
REQUEST DBFCDX
REQUEST DBFFPT
REQUEST ADS
RddRegister( "ADS", 1 )
RddSetDefault("ADS")
SET SERVER REMOTE
SET FILETYPE TO ADT
SET(_SET_AUTORDER,1)
SET AUTOPEN ON
set(_SET_OPTIMIZE,.T.)
ADSLOCKING(.T.)

SET DATE BRITISH
SET DELETED ON
SET CENTURY ON

Return nil

*****************************************************************************
function SetCookie( cName, cValue, nSecs, cPath, cDomain, lHttps, lOnlyHttp )
local cCookie := ''

hb_default( @cName, '' )
hb_default( @cValue, '' )
hb_default( @nSecs, 86400 )
hb_default( @cPath, '/' )
hb_default( @cDomain    , '' )
hb_default( @lHttps, .F. )
hb_default( @lOnlyHttp, .F. )

cCookie += cName + '=' + cValue + ';'
if nSecs # 0
    cCookie += 'max-age=' + alltrim(str( nSecs )) + ';'
endif
if !empty(cPath)
    cCookie += 'path=' + cPath + ';'
endif

MH_Header( "Set-Cookie", cCookie )

return nil

*********************
function GetCookies()

   local hHeadersIn := MH_HeadersIn()
   local cCookies := If( hb_HHasKey( hHeadersIn, "Cookie" ), hb_hGet( hHeadersIn, "Cookie" ), "" )
   local aCookies := hb_aTokens( cCookies, ";" )
   local cCookie, hCookies := {=>}

   for each cCookie in aCookies
      hb_HSet( hCookies, SubStr( alltrim(cCookie), 1, At( "=", alltrim(cCookie) ) - 1 ),;
               SubStr( alltrim(cCookie), At( "=", alltrim(cCookie)) + 1 ) )
   next

return hCookies


And this the simple prg
Code (fw): Select all Collapse
// {% LoadHRB( "retedb.hrb" ) %}

**************************************************************************
Function main()

Setting_db()

SetCookie( 'blu1', "cookie numero 1", 90000 )

Return nil


Running this simple prg I have this error

Code (fw): Select all Collapse
Errore del server!
Il server ha generato un errore interno e non è in grado di soddisfare la richiesta.

Messaggio di errore:
malformed header from script 'test_cookie.prg': Bad header: Set-Cookie

Se pensi che questo sia un errore del server, per favore contatta il webmaster.

Error 500
localhost
Apache/2.4.39 (Win64) OpenSSL/1.0.2s PHP/7.1.30 mod_fcgid/2.3.9
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Migration to the new mod_harbour fastCGI
Posted: Mon Jul 27, 2020 10:19 AM

ok, we are checking it. thanks!

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Migration to the new mod_harbour fastCGI
Posted: Tue Jul 28, 2020 06:55 AM

Massimo,

Please remove the functions SetCookie() and GetCookies() from your HRB file, build it and try it again

many thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Migration to the new mod_harbour fastCGI
Posted: Tue Jul 28, 2020 03:34 PM
Hi Antonio.
This is the prg, with the Setcookie function (taken from the samples) inside the prg
Code (fw): Select all Collapse
Function main()

SetCookie( 'blu', "cookienumber1" )

Return nil

function SetCookie( cName, cValue, nSecs, cPath, cDomain, lHttps, lOnlyHttp ) 

   local cCookie := ''
    
   // check parameters
   hb_default( @cName, '' )
   hb_default( @cValue, '' )
   hb_default( @nSecs, 3600 )   // Session will expire in Seconds 60 * 60 = 3600
   hb_default( @cPath, '/' )
   hb_default( @cDomain , '' )
   hb_default( @lHttps, .F. )
   hb_default( @lOnlyHttp, .F. )    
    
   // we build the cookie
   cCookie += cName + '=' + cValue + ';'
   cCookie += 'expires=' + CookieExpire( nSecs ) + ';'
   cCookie += 'path=' + cPath + ';'
   cCookie += 'domain=' + cDomain + ';'
        
   // pending logical values for https y OnlyHttp

   // we send the cookie
   MH_Header( "Set-Cookie", cCookie )

return nil

//----------------------------------------------------------------//
// CookieExpire( nSecs ) builds the time format for the cookie
// Using this model: 'Sun, 09 Jun 2019 16:14:00'

function CookieExpire( nSecs )

   local tNow := hb_datetime()  
   local tExpire   // TimeStampp 
   local cExpire   // TimeStamp to String
    
   hb_default( @nSecs, 60 ) // 60 seconds for this test
   
   tExpire = hb_ntot( ( hb_tton( tNow ) * 86400 - hb_utcoffset() + nSecs ) / 86400 )

   cExpire = cdow( tExpire ) + ', ' 
         cExpire += AllTrim( Str( Day( hb_TtoD( tExpire ) ) ) ) + ;
         ' ' + cMonth( tExpire ) + ' ' + AllTrim( Str( Year( hb_TtoD( tExpire ) ) ) ) + ' ' 
   cExpire += AllTrim( Str( hb_Hour( tExpire ) ) ) + ':' + AllTrim( Str( hb_Minute( tExpire ) ) ) + ;
              ':' + AllTrim( Str( hb_Sec( tExpire ) ) )

return cExpire


and this is the result
Code (fw): Select all Collapse
Errore del server!
Il server ha generato un errore interno e non è in grado di soddisfare la richiesta.

Messaggio di errore:
malformed header from script 'test_cookie.prg': Bad header: Set-Cookie

Se pensi che questo sia un errore del server, per favore contatta il webmaster.

Error 500
localhost
Apache/2.4.39 (Win64) OpenSSL/1.0.2s PHP/7.1.30 mod_fcgid/2.3.9
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Migration to the new mod_harbour fastCGI
Posted: Wed Jul 29, 2020 05:50 AM

Massimo,

function SetCookie() and CookieExpire() are already inside modharbour.exe

thats why I am asking you to remove them from your code, thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Migration to the new mod_harbour fastCGI
Posted: Wed Jul 29, 2020 06:16 PM
Antonio,
sorry, I misunderstood your advice. I was thinking that I must remove that functions from the HRB and place them in the prg.
I've removed them and now everything seems to work correctly. I'll make some more tests. And the speed is really better.
You must change the name in Fivetech & Furious
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Migration to the new mod_harbour fastCGI
Posted: Thu Jul 30, 2020 08:25 AM

Massimo,

great!

thanks so much for your great feedback :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com