Using threads from mod_harbour

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!
Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Using threads from mod_harbour

Post by Antonio Linares »

Live demo:
https://fivetechsoft.github.io/snippets/?20200211200801

Code: Select all

function Main()

   hb_ThreadStart( @Execute(), MemoRead( "/var/www/html/modharbour_samples/test.prg" ) )

   hb_threadWaitForAll()

   ? "ok"

return nil
Threads documentation:
https://github.com/Petewg/harbour-core/ ... iThreading
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Using threads from mod_harbour

Post by Antonio Linares »

Checking if the multithreading support is enabled and checking the amount of threads:

Code: Select all

function Main()

   ? hb_mtvm()   
   ? __vmCountThreads()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
thefull
Posts: 720
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona
Contact:

Re: Using threads from mod_harbour

Post by thefull »

ANTONIO WOOONNDERFUUULLLLL!!!!...
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Using threads from mod_harbour

Post by Antonio Linares »

Code: Select all

function Main()

   local n

   for n = 1 to 10
      hb_threadStart( @ReadWeb() )
   next

   InKey( 0.1 )

return nil

function ReadWeb()

   local oHttp := win_oleCreateObject( "MSXML2.XMLHTTP" ) // "MSXML2.ServerXMLHTTP" )

   ErrorBlock( { | o | AP_RPuts( "From thread: " + Str( hb_threadId() ) + "<br>" ),;
                       AP_RPuts( GetErrorInfo( o ) ),;
                       AP_RPuts( "<hr>" ), __Quit() } )

   oHttp:Open( "GET", "http://localhost/modharbour_samples/info.prg", .T. ) // synchronous
   oHttp:setRequestHeader( "pragma", "no-cache" )
   oHttp:setRequestHeader( "Cache-Control", "no-cache, no-store" )
   oHttp:SetRequestHeader( "Accept", "*/*" )
   oHttp:SetRequestHeader( "Content-Type", "application/x-www-form-urlencoded" )
   oHttp:Send()

   // while oHttp:readyState != 4  
   //    oHttp:WaitForResponse( 1000 )
   // end

   ? oHttp:ResponseText
   // ? oHttp:getAllResponseHeaders()
   // ? oHttp:Status
   ? oHttp:ClassName()

return nil
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Using threads from mod_harbour

Post by Antonio Linares »

Code: Select all

#include "/home/user/harbour/contrib/hbcurl/hbcurl.ch"

function Main()

   local n
   
   for n = 1 to 10
      hb_threadStart( @ReadWeb() )
   next
   
   hb_threadWaitForAll()
   InKey( 1 )    
   
return nil   

function ReadWeb()
    
    local hCurl, cBuffer := ""
    local cUrl  := "http://www.modharbour.org/modharbour_samples/test.prg"

    curl_global_init()  
    
    if ! empty( hCurl := curl_easy_init() )
        curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
        curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )

        if curl_easy_perform( hCurl ) == 0
            ? hb_threadId()
            ? curl_easy_dl_buff_get( hCurl )
            ? "<hr>"
        endif
    endif
    
    curl_global_cleanup()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply