Well this has really floored me. I am writing some PHP code to extract a list of waiting eQSLs and send replies where they match records from my log. In essence this is all straightforward but I have run into an issue that I as yet cannot resolve cleanly. There is some interaction I’m not seeing.

The eQSL API is a ColdFusion script accessed via crafting a URL with username and password. This returns a web page while at the same time preparing a list of waiting eQSLs as both an ADIF and a text file. I want the text file. The returned page has links to both and the files are not protected. When carried out by hand one clicks the link and the file is returned in the browser.

An ideal method to be automated and the kind of thing I’ve been doing since around the mid-1990s.

So, my PHP code first sends the API request and gets the returned webpage via cURL. It parses the page and extracts the URL of the text file that is the list of eQSLs. And it is here that it falls apart. When I pass this URL to another cURL procedure and thence a parser to extract the cards it always returns a 404 error.

Now the funny part. If instead of continuing in the code and using cURL to grab the produced text file I pass the URL via a system() call to another PHP program that contains the next cURL and parser that works just fine every time. And it’s the same variable I used to continued fail, or to call via system() and work, so the URL in it is correct.

I wondered at first if the ColdFusion code does not actually produce the file – or close the file – for a few seconds. But adding a delay did not work. So, does the remote code not finish things off while the network connection persists? I added various code to the two cURL processes to, in theory anyway, ensure the connection is closed after the first one. No joy.

If I simply print the URL of the download file and paste it into a browser, or into a different browser it all works. It just will not work from within that first script.

I can live with this but it’s nagging me… why is this happening? What else is PHP doing in the background that means that if I close the code and reopen another it all works? This has crept outside both my knowledge and experience! This is of course no fault of eQSL and stems from my desire to make things just the way I like them.

Categories

Tags

Recent Posts

Archives

Links