0

I've got two scripts that run separate from each other but are both used on the same page. One generates a PDF, and the other makes a call to an external API. Both scripts use curl.

On the page, an AJAX request is used to call the PHP script that calls the API. It also displays links the user can click to generate the PDF. The problem is when I try to generate the PDF, it has to wait until the other script that calls the API finishes. When there's a connection problem, that means long waits for the user.

From what I can tell, this happens because both scripts use curl, and the PDF one has to wait for the API one to finish it's curl call. I only have access to edit the API script. What I've done at the moment is set a timeout of 10 seconds to limit how long the user has to wait for the other script to finish, but I'd like to make it work so that the one script doesn't need to wait for the other to finish.

Is that possible with PHP? I tried switching from curl to file_get_contents, but it still waits for the other script to finish. And I assume a solution like curl_multi wouldn't help here since I can't edit one of the scripts.

2
  • Do you include the API and PDF script into your current running script or do you call them with CURL? Commented Mar 11, 2016 at 9:28
  • The one that calls the API is called via an AJAX request. The one that generates the PDF is called via a link. They are completely separate scripts that run separately, but both make external calls with curl. Commented Mar 11, 2016 at 10:13

1 Answer 1

1

Nevermind, the problem actually had nothing to do with curl. It had to do with the session, which both scripts use. The session couldn't be started in the PDF script until it was closed in the API script.

The solution was to grab the info I needed at the beginning of the API script and then close it with session_write_close() so that the other script could use it.

So even though this doesn't really answer the question, since I misunderstood the problem, this question doesn't really have a good answer. I'll leave this question and answer here just in case someone else runs into a similar problem...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.