0

I am new to PHP. I have a block of code on my webpage which I want to execute asynchronously. This block has following :
1. A shell_exec command.
2. A ftp_get_content.
3. Two image resize.
4. One call to mysql for insert.

Is there way make this block async, So that the rest of the page loads quickly. Please ask if any more details required.

1
  • What will it do with the resultof ftp_get_content? If it's going to be included on the page, then nothing can be sent to the client until this is done. Commented May 12, 2013 at 11:15

2 Answers 2

1

One possible solution is to use curl to do a pseudo async call. You can put the async part of your code in a separate php file and call it via curl. For example:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'YOUR_URL_WITH_ASYNC_CODE');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1);

curl_exec($ch);
curl_close($ch);
Sign up to request clarification or add additional context in comments.

1 Comment

I have used this curl_setopt($ch, CURLOPT_URL, dirname(__FILE__).'/getlargestimageasync.php?url='.$user_url);, but its not working.
0

You could put the 4 tasks into a queue, maybe something like Beanstalkd, then have a background worker process this queue.

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.