Page 1 of 1
How to clear the socket cache.
Posted: Wed Sep 02, 2015 10:19 am
by lilRalph
Hi folks, I am trying to build an app to put posts on my Wordpress sites.
I would like to do this with LiveCode because of the multi-platform capability.
Part of this is the requirement to login to the site and navigate to the posts part of the dashboard.
To stay logged in to Wordpress it is essential to manage the cookies and follow redirects.
I have done this using Python, Phantomjs, Pure Basic and simpletest (a PHP unit testing framework).
I couldn't get it to work with TCL/TK or Freepascal so I do understand the process and that it is a non-trivial process.
I wrote my first serious program with Hypercard in the late 80's, a cash register program for a service station, and am delighted to be reacquainted with it through LiveCode.
Having established some slight credentials let's get to the problem.
I am getting intermittent and unreliable logging. I have crawled the forums for post type comments but nothing seems to cover the issue I am having.
It seems to me that LC caches the http headers and returns them regardless of the URL I call.
Sometimes it even seems to cache the headers I send and resend them instead of the proper ones.
I have attached a sample stack which demonstrated the problem.
Changing the URL in the URL field works for the first few times but then it starts to get hung up and returns the same recieved headers almost regardless of the requested site.
I test with google, amazon, ebay, adobe, apple, microsoft, gmail etc. but you can also test with pretty much any site you like, the behaviour remains unreliable.
What have I missed? Is this really buggy behaviour ir is it me?
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 10:32 am
by scrabbles
Hi ya,
If you are using the "load" command, there is a counterpart called "unload" that should clear the cache. Additionally, you can see what URLs have been cached by using "the cachedURLs" to verify.
Hope that helps.
- Mark
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 10:34 am
by lilRalph
Thanks for the quick response.
I thought I had attached the stack but 'twasnt so.
It is now.
You will see in that that I am using load and unload but the behaviour remains buggy.
I will test the cachedUrls call though.
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 10:36 am
by Thierry
lilRalph wrote:Thanks for the quick response.
I thought I had attached the stack but 'twasnt so.
It is now.
Hi Ralph,
You can't attached a file right now; I think you need few more posts
to be able to do that...
Put ti in your dropbox or anywhere and provide a link to it.
Regards,
Thierry
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 10:40 am
by lilRalph
G'Day Thierry, my first post appears to me to have a downloadable link to the file at the top of the post.
If that isn't the same for you then I'll make alternative arrangements.
I just tried the cachedUrls function and it shows empty while I am requesting amazon and getting ebay headers.
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 11:02 am
by Thierry
lilRalph wrote:G'Day Thierry, my first post appears to me to have a downloadable link to the file at the top of the post.
Oops, sorry for the noise. There it is
Regards,
Thierry
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 11:54 am
by Thierry
Hi,
Managed to make it works with few changes..
Code: Select all
function fnGetStaticHeaders pHost, pCookies,pReferer
put empty into tHeaders
-- if pHost is not empty then put "Host:" && pHost & cr into tHeaders
put cr & "User-Agent: " "e&"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0""e after tHeaders
put cr & "Accept: " "e&"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8""e after tHeaders
put cr & "Accept-Language: " "e&"en-gb,en;q=0.5""e after tHeaders
put cr & "Accept-Encoding: " "e&"gzip,deflate""e after tHeaders
put cr & "Connection: " "e&"keep-alive""e after tHeaders
-- if pReferer is not empty then
-- put cr & "Referer:" && pReferer after tHeaders
-- end if
-- if pCookies is not empty then
-- put cr & "Cookie: lang=english;" & pCookies after tHeaders
-- end if
return tHeaders
end fnGetStaticHeaders
BTW, I'm working on a current project which just does what you want,
and I'm quite happy so far with all the tests...
HTH,
Thierry
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 11:56 am
by Thierry
and I changed this settings to have some feedback:
Code: Select all
libURLFollowHttpRedirects false -- true
Thierry
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 12:23 pm
by lilRalph
Thierry that does work and it seems to be reliable. Excellent work.
It is very interesting that putting the quotes around the text makes a difference, I am supposing that LC treats it as a string then as opposed to objects (?).
However, I will need to have the cookies at the very least because, as you would know, Wordpress relies on the cookies for access.
I am happy to not have to use socket manipulation directly.
OK, not a bug.
Thanks.
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 12:30 pm
by Thierry
lilRalph wrote:Thierry that does work and it seems to be reliable. Excellent work.
Glad that you're happy with it
It is very interesting that putting the quotes around the text makes a difference, I am supposing that LC treats it as a string then as opposed to objects (?).
Well, reading closely at headers, those quotes are mandatories.
And yes, it's just plain text.
However, I will need to have the cookies at the very least because, as you would know, Wordpress relies on the cookies for access.
Check in these forums for an excellent post from sparkout, who explains very nicely and
precisely how to deal with cookies.
Regards,
Thierry
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 12:58 pm
by lilRalph
Thanks again Thierry, I removed this bit
-- if pHost is not empty then put "Host:" && pHost & cr into tHeaders
as I found that LC puts in the Host: part correctly.
Removing that part enables the cookies to operate.
I will check out sparkout's cookie handling.
For those who read this later, the link to sparkout's cookie handling is here
http://forums.livecode.com/viewtopic.ph ... ers#p86063 .
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 1:22 pm
by Thierry
lilRalph wrote:Thanks again Thierry, I removed this bit
-- if pHost is not empty then put "Host:" && pHost & cr into tHeaders
as I found that LC puts in the Host: part correctly.
Removing that part enables the cookies to operate.
As I did the first corrections quite fast, it seeems we do *not* need ot add these extra quotes!
So the problem was certainly the double Host definition...
Yep, that's the one
So you're in good hands with sparkout expertise
Good lck,
Thierry
Re: How to clear the socket cache.
Posted: Wed Sep 02, 2015 7:20 pm
by SparkOut
Just for info, the pHost argument there was optional, I included it in the function because it was necessary for the specific site in question on that thread. It would have been better if I had mentioned it, and perhaps more succinctly, would have been better to have made the pHost argument the last one passed to the function, in which case it would be more elegant to leave it out optionally. (On the other hand, all the arguments are optional).
Re: How to clear the socket cache.
Posted: Fri Sep 04, 2015 12:58 pm
by lilRalph
Great forum response here. Fast, accurate and not agressive or belittling like some forums.
Keep up the great customer service here and LiveCode is destined for greatness.
Thanks Thierry for your help and feedback. I have also tested the quotes and decided to leave them in even though they seem to be essential.
Thanks also to sparkout for your input. I had read that the headers are replaced rather than required but updating the host shouldn't upset the routine.
I have plans for this programming tool, I hope I'm up to it.