473,657 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

run a php in the background using http

Hi,

i have a script (script1) which needs to call another script (script2).
It should not wait for the answer, so script2 should run in the background.

I really need to call the php script using:
http://urlof myscript/script2.php

I don't want to use it as a cgi and use CLI.

I did a test with fsockopen and curl and a timeout of 10 seconds and call
http://urlof myscript/script1.php from my browser:
Script1 stops after 10 seconds => OK
Script2 has been called by script1 and continue to run in the background
=>OK
After 60 seconds Script2 is killed by php!! => KO :(

The script is working fine if i call http://urlof myscript/script2.php from
my browser. It needs around 120 seconds to finish.

Why is it stopping after 60 seconds when I use fsockopen and call it from
script1?

Here is the script in SCRIPT1:
$fp = fsockopen("$hos t", 80, $errno, $errstr, 30);
stream_set_time out($fp,10);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection : Close\r\n\r\n";

fwrite($fp, $out);
$status = socket_get_stat us($fp);

while (!feof($fp) && !$status['timed_out']) {
echo fgets($fp, 128);
$status = socket_get_stat us($fp);
}
fclose($fp);
}
I have added this in SCRIPT2:
ignore_user_abo rt(FALSE); // becareful, FALSE really means it should ignore
user abort !!!
set_time_limit (120);
ini_set("max_in put_time",120);
ini_set("max_ex ecution_time",1 20);
Do you have any idea??

Thanks you for your help

Rod
Jul 17 '05 #1
12 3043
WebRod wrote:
Hi,

i have a script (script1) which needs to call another script (script2).
It should not wait for the answer, so script2 should run in the background.

I really need to call the php script using:
http://urlof myscript/script2.php

I don't want to use it as a cgi and use CLI.

I did a test with fsockopen and curl and a timeout of 10 seconds and call
http://urlof myscript/script1.php from my browser:
Script1 stops after 10 seconds => OK
Script2 has been called by script1 and continue to run in the background
=>OK
After 60 seconds Script2 is killed by php!! => KO :(

The script is working fine if i call http://urlof myscript/script2.php from
my browser. It needs around 120 seconds to finish.

Why is it stopping after 60 seconds when I use fsockopen and call it from
script1?

Here is the script in SCRIPT1:
$fp = fsockopen("$hos t", 80, $errno, $errstr, 30);
stream_set_time out($fp,10);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection : Close\r\n\r\n";

fwrite($fp, $out);
$status = socket_get_stat us($fp);

while (!feof($fp) && !$status['timed_out']) {
echo fgets($fp, 128);
$status = socket_get_stat us($fp);
}
fclose($fp);
}
I have added this in SCRIPT2:
ignore_user_abo rt(FALSE); // becareful, FALSE really means it should ignore
user abort !!!
set_time_limit (120);
ini_set("max_in put_time",120);
ini_set("max_ex ecution_time",1 20);
Do you have any idea??

Thanks you for your help

Rod


Why not exec() it?

exec("nohup /path/to/php /path/to/script2.php &");

I used something similar to launch mpg123 when I was playing around with
a web-based media player.

NM

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #2

"WebRod" <no****@bouygte l.fr> wrote in message
news:42******** *************** @news.club-internet.fr...
Hi,

i have a script (script1) which needs to call another script (script2).
It should not wait for the answer, so script2 should run in the background.
I really need to call the php script using:
http://urlof myscript/script2.php

I don't want to use it as a cgi and use CLI.

I did a test with fsockopen and curl and a timeout of 10 seconds and call
http://urlof myscript/script1.php from my browser:
Script1 stops after 10 seconds => OK
Script2 has been called by script1 and continue to run in the background
=>OK
After 60 seconds Script2 is killed by php!! => KO :(

The script is working fine if i call http://urlof myscript/script2.php from my browser. It needs around 120 seconds to finish.

Why is it stopping after 60 seconds when I use fsockopen and call it from
script1?

Here is the script in SCRIPT1:
$fp = fsockopen("$hos t", 80, $errno, $errstr, 30);
stream_set_time out($fp,10);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection : Close\r\n\r\n";

fwrite($fp, $out);
$status = socket_get_stat us($fp);

while (!feof($fp) && !$status['timed_out']) {
echo fgets($fp, 128);
$status = socket_get_stat us($fp);
}
fclose($fp);
}
I have added this in SCRIPT2:
ignore_user_abo rt(FALSE); // becareful, FALSE really means it should ignore user abort !!!
set_time_limit (120);
ini_set("max_in put_time",120);
ini_set("max_ex ecution_time",1 20);
Do you have any idea??

Thanks you for your help

Rod


It would help if you use ignore_user_abo rt() correctly.
ignore_user_abo rt(true) means ignore user abort.
Jul 17 '05 #3
News Me wrote:
WebRod wrote:
Hi,

i have a script (script1) which needs to call another script (script2).
It should not wait for the answer, so script2 should run in the
background.


Why not exec() it?

exec("nohup /path/to/php /path/to/script2.php &");

I used something similar to launch mpg123 when I was playing around with
a web-based media player.


'cos:
1) the OP said he didn't want to run it from the CLI
2) it's part of the same process group so the original script will hang
around while it's running (hint: use 'at now ...' instead of '...&'

C.

Jul 17 '05 #4
> It would help if you use ignore_user_abo rt() correctly.
ignore_user_abo rt(true) means ignore user abort.


actually with windows xp sp2 and php 4.3.10, it's the opposite.
ignore_user_abo rt(false) means ignore user abort.

with linux
ignore_user_abo rt(true) means ignore user abort.
Rod

Jul 17 '05 #5
NC
WebRod wrote:

i have a script (script1) which needs to call another script (script2). It should not wait for the answer, so script2 should run in the background.
I really need to call the php script using:
http://urlof myscript/script2.php

I don't want to use it as a cgi and use CLI.
OK, then use wget and fork its execution into background.
Why is it stopping after 60 seconds when I use fsockopen
and call it from script1?


Perhaps your system has an execution time limit not overridable
from the scripts?

Cheers,
NC

Jul 17 '05 #6

"WebRod" <no****@bouygte l.fr> wrote in message
news:42******** **************@ news.club-internet.fr...
It would help if you use ignore_user_abo rt() correctly.
ignore_user_abo rt(true) means ignore user abort.


actually with windows xp sp2 and php 4.3.10, it's the opposite.
ignore_user_abo rt(false) means ignore user abort.

with linux
ignore_user_abo rt(true) means ignore user abort.


I don't know where you got your info from, pal, but it is wrong.

main.c, line 1759

/* {{{ php_handle_abor ted_connection
*/
PHPAPI void php_handle_abor ted_connection( void)
{
TSRMLS_FETCH();

PG(connection_s tatus) = PHP_CONNECTION_ ABORTED;
php_output_set_ status(0 TSRMLS_CC);

if (!PG(ignore_use r_abort)) {
zend_bailout();
}
}
/* }}} */

Jul 17 '05 #7
Colin McKinnon wrote:
News Me wrote:

WebRod wrote:
Hi,

i have a script (script1) which needs to call another script (script2).
It should not wait for the answer, so script2 should run in the
background .


Why not exec() it?

exec("nohup /path/to/php /path/to/script2.php &");

I used something similar to launch mpg123 when I was playing around with
a web-based media player.

'cos:
1) the OP said he didn't want to run it from the CLI
2) it's part of the same process group so the original script will hang
around while it's running (hint: use 'at now ...' instead of '...&'


1) The OP is not running it from the command line, the webserver is.
2) When I ran the script on a Fedora Core System, it didn't hang.

NM

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #8
> I don't know where you got your info from, pal, but it is wrong.

Actually i did a small test to ckeck that.
The same test (script 1 is calling script2 using fsockopen and a small
timeout):

ignore_user_abo rt(true)
- windows => script2 stops WHEN script 1 stops (!!)
- linux => script2 will stop only at the end. (as expected)

ignore_user_abo rt(false)
- windows => script2 will stop only at the end. (!!)
- linux => script2 stops WHEN script 1 stops (as expected)

Maybe i have a corrupted version of php??
I have windows XP SP2, php 4.3.10

Rod
Jul 17 '05 #9
1) The OP is not running it from the command line, the webserver is.

Actually it's the same thing.
I explain you why I don't want to use it. My web server is on OVH.COM.
My script running from the CLI (from telnet or exec) use too many
ressources (!!) on the server and they kill it and send me an email to stop
this script or they will disable my website!!
The same script (I just change the extension from .cg to .ph and remove the
first line which specify the php path) is running very well, they don't kill
it, no problem!!

They don't explain me why there is a difference, so i don't want to use the
CLI anymore with them.

Jul 17 '05 #10

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

Similar topics

7
5796
by: ryan.fairchild | last post by:
Ok I basically am creating a container for a bunch of other <div> tags. But I want to make four jpegs/gif/whatever that goes in each corner so they look rounded. I thought this is how I would do it but I could be wrong. body { background:#999 url("http://") no-repeat top left; background/* */:/**/url("http://") no-repeat top right; background: /**/url("http://") no-repeat top right;
8
3756
by: Ron Holmes | last post by:
I want to place a background image on a windows form. Is there a way to prevent the image from Tiling without using an image box resized to the size of the form? I am using Visual Studio 2003 .NET. This is an easy thing to do in VB6.
5
11084
by: proximus | last post by:
Hi, I am trying to change the background of table TD's. The problem is that I have no access to the HTML code. SO I am trying to alter this using Javascript/DOM in an external .js file. I have tried lot's of things and spent hours on this, I thought I might give it a try here. One of the TD's uses HTML to set the background, the other one uses CSS styling:
7
5123
by: Nilesh | last post by:
I am using background-image attribute in a CSS file and linking the CSS file to aspx page. But strangly, background-image attribute is not working for relative URL. e.g. If I apply following css ..navbar-background { background-image: url(images/menubar.gif); } the image is not appearing on the page. It seems that IE is picking
3
3230
by: Viken Karaguesian | last post by:
Hello all, I need somehelp with background tiling. I have a sneaking suspicion that what I want to do is not possible, but I'll ask anyway. :>) First some background: Here's the site in question: www.sayatnova.com (I'm sure many of you have seen this before as I've often asked for help). I've come a long way since I first created the site many moons ago and I'm trying to convert it to a (1) Table-less, (2) Frame-less and (3) Validated...
2
22053
by: Mark | last post by:
IE creates an object of every ID'd HTML tag (so it appears), and each object sets a property for any parameter I set in the tag. For example, my HTML might be: <td id='cell1' background='myimg.jpg' width='30'... </tdwhich IE will use to create a Javascript object called 'cell1' with properties of background and width, like so: cell1.background would have a value of 'myimg.jpg' and cell1.width would have a value of 30. I can change the...
8
5352
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In this code there is a panel panel1, that I populate with a lable in the foreground. Then when I click on "button1" a backgroundworker thread in async mode is started. When the backgoundworker thread completes the thread returns a panel to populate...
8
10162
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background however shows white as the PictureBox moves but I want it to be transparent. The PictureBox BackColor is set to Transparent .. but no affect. I have used PhotoShop to make the image background transparent .. again no affect. If I make the image a...
2
4805
XedinUnknown
by: XedinUnknown | last post by:
Hi! I am new to this forum, but not new to web design and programming. Nevertheless, I have never tried to use PNG so extensively in my pages. here's the problem. First, I have found that the PNG backgrounds and images had no transparency and grey around them when viewed in IE6, but I solved this bug using this hack. It works great, but then another problem came up: a background image that had the solution applied to was not repeating...
2
14067
by: thephatp | last post by:
I'm having a problem with IE rendering correctly. I'm experimenting with using all div's in my pages now, and I'm not very familiar with the quirks of IE. I have created a sample page, and I'm really confused as to what is going on in IE. FF renders the page exactly as I expect. IE renders the page with everything in the correct location, but it seems to double the background image for a sub-div section that is moved up using a negative...
0
8399
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
8732
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
8504
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
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4159
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...
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1622
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.