Page 1 of 1
Using threads from mod_harbour
Posted: Tue Feb 11, 2020 8:19 pm
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
Re: Using threads from mod_harbour
Posted: Tue Feb 11, 2020 8:27 pm
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
Re: Using threads from mod_harbour
Posted: Thu Feb 13, 2020 12:49 pm
by thefull
ANTONIO WOOONNDERFUUULLLLL!!!!...
Re: Using threads from mod_harbour
Posted: Sun Feb 16, 2020 11:31 am
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
Re: Using threads from mod_harbour
Posted: Sun Feb 16, 2020 3:10 pm
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