Link to home
Start Free TrialLog in
Avatar of CrisThompsonUK
CrisThompsonUKFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Asynchronous PHP (that old chestnut)

Hi.

I have a client calling my server script, doing stuff, and replying...

But one of the things it's doing it taking a while, and so I don't want the main process to wait before it replies, instead I want it to fire off a little PHP script to get on with it, so it can reply to the user as soon as possible.

How to do this?

I have quickly tried exec, and fsocketopen, but my child php is not executing, and I don't know how to trap the error.  There is nothing in my error logs.

Can someone give me the statements to do this, so I can get on writing the code that gets executed.

Thanks,

Cris.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CrisThompsonUK

ASKER

Thanks Ray,

Looks great.  I'll check it out monday,

Regards,

Cris
Morning.

This is starting to work, but I'm getting a CURL connection error 7.

I have tried connecting to google using this code, and it works fine, so it's my URL...

I'm developing on a system with a domain reference so it's:
 
http://79.170.40.236/twm-test.co.uk/procedures/P4.1-NADTHREAD-0.1.php

This is not going to be stopping anything is it?

What else is going to cause the connection error?

Cris.
Here's the error:

CURL FAIL: http://79.170.40.236/twm-test.co.uk/procedures/P4.1-NADTHREAD-0.1.php TIMEOUT=3, CURL_ERRNO=7 : couldn't connect to host

array(22) {
  ["url"]=>
  string(69) "http://79.170.40.236/twm-test.co.uk/procedures/P4.1-NADTHREAD-0.1.php"
  ["content_type"]=>
  NULL
  ["http_code"]=>
  int(0)
  ["header_size"]=>
  int(0)
  ["request_size"]=>
  int(0)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0)
  ["namelookup_time"]=>
  float(0.000167)
  ["connect_time"]=>
  float(0)
  ["pretransfer_time"]=>
  float(0)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(-1)
  ["upload_content_length"]=>
  float(-1)
  ["starttransfer_time"]=>
  float(0)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["redirect_url"]=>
  string(0) ""
}
From my computer, the Internet DNS allows me to connect to:
http://79.170.40.236/twm-test.co.uk/procedures/P4.1-NADTHREAD-0.1.php

... where I see:
DEBUG: Connection Status: 1
array(0) { }

I expect that there is something in your local DNS that could be causing the attempt to resolve to fail, but I can't imagine what it might be.  You might consider putting the cURL scripts on two separate servers, addressable by two separate URLs.  This would cause the DNS resolution to have to go to the internet DNS.  That would eliminate the chance that a local DNS setting is causing the problem.

http://79.170.40.236/ yields a blank page
http://79.170.40.236/twm-test.co.uk/ yields a test menu page
http://79.170.40.236/twm-test.co.uk/procedures/ yields a 403 Forbidden
Thanks Ray,

You see what it's currently doing...

My host said that the domain reference will refuse the loopback call, and suggested I use the secure server connection location on the CURL.

This is just a test setup, the actual implementation will be done by someone else...

Will post results...
It's working now.

My host didn't like the CURL being on the same server - 'causing a loopback', so I'm using the secure server version of the location of the file for the call.

thanks again Ray.
Glad to help.  Thanks for the points, ~Ray
gonna love async. php...