Using threads from mod_harbour

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

Using threads from mod_harbour

Postby Antonio Linares » Tue Feb 11, 2020 8:19 pm

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

Code: Select all  Expand view
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/wiki/MultiThreading
regards, saludos

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

Re: Using threads from mod_harbour

Postby Antonio Linares » Tue Feb 11, 2020 8:27 pm

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

Code: Select all  Expand view
function Main()

   ? hb_mtvm()  
   ? __vmCountThreads()

return nil
regards, saludos

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

Re: Using threads from mod_harbour

Postby thefull » Thu Feb 13, 2020 12:49 pm

ANTONIO WOOONNDERFUUULLLLL!!!!...
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
thefull
 
Posts: 730
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona

Re: Using threads from mod_harbour

Postby Antonio Linares » Sun Feb 16, 2020 11:31 am

Code: Select all  Expand view
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: 41449
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using threads from mod_harbour

Postby Antonio Linares » Sun Feb 16, 2020 3:10 pm

Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 41449
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 11 guests