473,794 Members | 2,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Continuing PHP script after HTTP reply is sent

I have a PHP script that is run via a 'wget' command within
an MS SQL trigger, and relies on accessing the database
record updated by the SQL statement that triggered the
script in the first place.

For this reason, to avoid the script reading the old record
or getting into a deadly embrace, it must "return" in order
to complete the 'wget' command but then carry on and do the
actual work required.

Does anyone know how or if this can achieved using PHP?

(I tried web searches to obtain a solution and checked the
FAQ; but, as so often, unless one knows the "magic phrase"
this is fruitless!)

I wondered about a self-redirect. But wouldn't 'wget' then
have to wait for the output from the redirected PHP script
so I'd be back to square one?
Cheers

John R Ramsden (jo**********@s agitta-ps.cam) <-- com not cam
Jul 17 '05 #1
4 2517
On 4 Jun 2004 07:31:24 -0700, jo**********@sa gitta-ps.com (John
Ramsden) wrote:
I have a PHP script that is run via a 'wget' command within
an MS SQL trigger, and relies on accessing the database
record updated by the SQL statement that triggered the
script in the first place.

For this reason, to avoid the script reading the old record
or getting into a deadly embrace, it must "return" in order
to complete the 'wget' command but then carry on and do the
actual work required.

Does anyone know how or if this can achieved using PHP?

(I tried web searches to obtain a solution and checked the
FAQ; but, as so often, unless one knows the "magic phrase"
this is fruitless!)

I wondered about a self-redirect. But wouldn't 'wget' then
have to wait for the output from the redirected PHP script
so I'd be back to square one?


Re-directs (as in sending a HTTP "Location" header) ask the user agent
to issue another HTTP request for the named resource. AFAIK, wget
doesn't pay attention to that HTTP header; I didn't see an option for
it in the wget man page.

Some suggestions:

- In your trigger, you could pass in the required values from the
record as parameters to the php script.

- If the script (and PHP) resides on your DB server, you can call it
via the command line rather than through an HTTP server.

- Depending on the complexity of the script, it may be possible to
re-write it in a stored procedure.

- Or write a stored procedure that ensures the update and the script
happen in the correct order.

--
David ( @priz.co.uk )
Jul 17 '05 #2
On 2004-06-04, David Mackenzie <me@privacy.net > wrote:
Re-directs (as in sending a HTTP "Location" header) ask the user agent
to issue another HTTP request for the named resource. AFAIK, wget
doesn't pay attention to that HTTP header; I didn't see an option for
it in the wget man page.


It does.
Apache sends a 3xx reply which means moved/redirected.

Connecting to <host>[<ip>]:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: <newurl> [following]

Bye,
phil
--
Please send replies (not followups) to the address set in Reply-To.
Philipp Kern - PK2186-RIPE - http://www.philkern.de
Jul 17 '05 #3
David Mackenzie <me@privacy.net > wrote in message news:<ge******* *************** **********@4ax. com>...
On 4 Jun 2004 07:31:24 -0700, jo**********@sa gitta-ps.com (John
Ramsden) wrote:
I have a PHP script that is run via a 'wget' command within


Many thanks for your replies David and Phil. I guess the simplest
solution would be for the PHP script to "fork off" another script
and then just finish.

I'm surprised there seems to be no way for PHP/Apache to run
a script that completes an HTTP request but can then continue
running, either indefinitely or as long as needed to perform
post-reply processing of some sort - kind of "send this reply
now, but I still have some work to do before exiting".

(That's just a summary of the basic problem, without all the
extraneous details. So if it rings any bells, don't hesitate
to add further thoughts guys!)
Cheers

John R Ramsden (jo**********@s agitta-ps.cam) <-- com not cam
Jul 17 '05 #4
jo**********@sa gitta-ps.com (John Ramsden) wrote
(in an article that hasn't yet turned up on my server):

I'm surprised there seems to be no direct way for PHP/Apache
to run a script that completes an HTTP request but can then
continue running, either indefinitely or as long as needed
to perform post-reply processing of some sort - kind of
"send reply now, but I still have some work to do before
exiting".


More rooting about on the web revealed that dozens of people
have asked the same question, but there is definitely no way
of doing this directly.

(It seems a reasonable requirement to me. But PHP internals
developers who have replied are dogmatic in their insistance
that it is a wrong thing to want to do, and I assume it will
never be supported.)

So, one must fall back on starting a background script. For
anyone who needs to do this, the following is an example I
have produced.

(I'd be interested if there is a more robust way to deduce
the OS platform, which works whether the script is run via
either HTTP or the command line, and I'd be very interested
if recent versions of PHP include an OS-independent function
for starting a background process!)

global $_SERVER;

if (array_key_exis ts ('argv', $_SERVER)) # Unix (HTTP or CLI)
{
proc_close (proc_open ("php jr_test_2.php &", array(), $foo));
}
else # Windows
{

# (_SERVER doesn't contain 'DOCUMENT_ROOT' record
# if the script is run from command line.
#
$path = array_key_exist s ('DOCUMENT_ROOT ', $_SERVER) ?
($_SERVER['DOCUMENT_ROOT'] . '/') : '';

proc_close (proc_open ("start /b php ${path}jr_test_ bg.php",
array(), $foo));
}

# Doesn't yet support other platforms, such as Macs
(At this point the background script jr_test_bg.php will be
running, and the script comprising the above code disconnects.
Needless to say the background script could be anything, e.g.
a perl script.)
Cheers

John R Ramsden (jo**********@s agitta-ps.cam) <-- com not cam
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4690
by: Jakej | last post by:
I've been using a javascript in an html file for a banner slider, and it works as desired. But I'd like to use it on more than one page and it would be great if I could transfer the code to a .js file and call it with the <script src="filename.js"></script> tags as I do for many other .js files. But, when I try to do that way, it doesn't work right. It will display the banner text, but only on the 0,0 page coordinate and doesn't slide....
2
2484
by: steve | last post by:
I'm trying to create a PHP script to send mail to a list of addresses. I'm sending mail okay, because the messages arrive in an account that I can check, but messages to a known bad address aren't being bounced back to the sending address. Here's the line of code I'm using: $mailok = mail("me@goodaddress.com,me@badaddress.com","this is a test", "this is a test", "From: me@sendaddress.com");
6
3398
by: Ivan Demkovitch | last post by:
Hi! Here is my problem: I'm inserting script for Trust Logo from one of the SSL authorities. It works fine when I do it in HTML, but I need to build it dynamically: HtmlTableRow tR = new HtmlTableRow(); HtmlTableCell tC1 = new HtmlTableCell(); tC1.Controls.Add(new LiteralControl("<script type=\"text/javascript\">TrustLogo(\"https://" +
11
11947
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not figure out how to reply to the thread per se using Google Groups and so please forgive me for cutting and pasting (I emailed him but he may not have time to check his email), and I am hoping someone might be able to tell me how I can change this...
2
3417
plumpnation
by: plumpnation | last post by:
I have now got this bulky piece of script working, it reads the form correctly, which sends the request to the web service using SOAP. It conforms to their DTD and the web service then responds and sends an xml document back to the page. I would very much like the contents of the form to be entered into an sql database as it is sent to the web service, as their reply does not contain the full details filled into the form. Aside from the...
3
11303
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
2
22999
krik
by: krik | last post by:
Hello, I would like to send a mail via a script with customized From field or at least with Reply-To. This email is sent by a monitoring server via a cron job and the users should see this mail as coming from the group mailbox I belong to. I haven't been able to find how to send a mail with a different address in the From but from the command line I can change the Reply-to (better than nothing). If I use the same in a script it doesn't...
5
1512
by: Joker7 | last post by:
Hi, I use the script below to send a email from a contact form but it would be nice if the conformed sent page showed what was sent.Question how can I do this ? Thanks Chris <?php $mailto = 'email@mail.co' ;
1
47492
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.