|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general-digest-help
lists.php.net
Date: Mon Sep 17 2007 - 22:33:11 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-general Digest 18 Sep 2007 03:33:11 -0000 Issue 5024
Topics (messages 262161 through 262190):
Try to find a solution, when restart Apache with PHP Script
262161 by: Rodolfo De Nadai
262162 by: Edward Kay
262163 by: Rodolfo De Nadai
262166 by: Jim Lucas
262167 by: Rodolfo De Nadai
262168 by: Jim Lucas
262169 by: Rodolfo De Nadai
262170 by: Jim Lucas
262171 by: Rodolfo De Nadai
262177 by: Daevid Vincent
262180 by: Rodolfo De Nadai
262186 by: Daevid Vincent
Re: Finding next recored in a array
262164 by: tedd
262165 by: brian
262174 by: Richard Kurth
262175 by: Jim Lucas
262176 by: Richard Kurth
262178 by: Jim Lucas
262179 by: brian
262181 by: Richard Kurth
262182 by: Richard Kurth
262184 by: Jim Lucas
262189 by: M. Sokolewicz
PHP "preg_replace" help
262172 by: Chaim Chaikin
262173 by: Jim Lucas
262188 by: Arpad Ray
PHPSESSID in links
262183 by: Kevin Murphy
262185 by: Stut
back-button question
262187 by: Πρεκατές Αλέξανδρος
262190 by: Eric Butera
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
Hi all...
I'm facing a serious problem with my application. I have a script write
in PHP that starts in Internet Explorer, this script keep on running
until a varible value change on my MySQL database.
The problem is that when i restart Apache, the process child initalized
isn't kill... then the apache can't be start because the script is use
the port 80.
To solve my problem, without change anything, the best would be that
when i execute the script, it run on other port than the default 80...
so this way apache could start...
The is a way to redirect through php, so the script run on a diferent
port?? Like change some line, or add on php.ini files?? or even in
programming??
thanks ... for any info
--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *
*Informtica de Municpios Associados S.A.*
Seu governo mais inteligente
rodolfo.denadai
ima.sp.gov.br <mailto:rodolfo.denadai
ima.sp.gov.br> -
www.ima.sp.gov.br <http://www.ima.sp.gov.br/>
Fone: (19) 3739-6000 / Ramal: 1307
attached mail follows:
> I'm facing a serious problem with my application. I have a script write
> in PHP that starts in Internet Explorer, this script keep on running
> until a varible value change on my MySQL database.
> The problem is that when i restart Apache, the process child initalized
> isn't kill... then the apache can't be start because the script is use
> the port 80.
>
> To solve my problem, without change anything, the best would be that
> when i execute the script, it run on other port than the default 80...
> so this way apache could start...
> The is a way to redirect through php, so the script run on a diferent
> port?? Like change some line, or add on php.ini files?? or even in
> programming??
>
The TCP port used is configured by Apache. You can't change this in PHP. In
any case, I very much doubt it would solve your problem since it will still
be blocking on whatever port you use.
To resolve this issue, you need to work on why IE is holding the connection
open. Perhaps a better solution is to simply have the client poll a PHP
script to determine when desired condtion occurs.
Edward
attached mail follows:
Edward , my best guess is that not IE is holding the connection but the
apache user... because the process is related to the apache user... and
there's more i can close IE, bacause i use the directive 2> log.log & on
the call of system.
Example:
system("php myscript.php 2> log.log &");
This why IE will not wait until the script is finish...
One thing i can't understand is why this child process of the apache
user is not killed when i restart apache... that's the real deal...
thanks
Edward Kay escreveu:
>> I'm facing a serious problem with my application. I have a script write
>> in PHP that starts in Internet Explorer, this script keep on running
>> until a varible value change on my MySQL database.
>> The problem is that when i restart Apache, the process child initalized
>> isn't kill... then the apache can't be start because the script is use
>> the port 80.
>>
>> To solve my problem, without change anything, the best would be that
>> when i execute the script, it run on other port than the default 80...
>> so this way apache could start...
>> The is a way to redirect through php, so the script run on a diferent
>> port?? Like change some line, or add on php.ini files?? or even in
>> programming??
>>
>>
> The TCP port used is configured by Apache. You can't change this in PHP. In
> any case, I very much doubt it would solve your problem since it will still
> be blocking on whatever port you use.
>
> To resolve this issue, you need to work on why IE is holding the connection
> open. Perhaps a better solution is to simply have the client poll a PHP
> script to determine when desired condtion occurs.
>
> Edward
>
>
>
>
--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *
*Informtica de Municpios Associados S.A.*
Seu governo mais inteligente
rodolfo.denadai
ima.sp.gov.br <mailto:rodolfo.denadai
ima.sp.gov.br> -
www.ima.sp.gov.br <http://www.ima.sp.gov.br/>
Fone: (19) 3739-6000 / Ramal: 1307
attached mail follows:
Rodolfo De Nadai wrote:
> Edward , my best guess is that not IE is holding the connection but the
> apache user... because the process is related to the apache user... and
> there's more i can close IE, bacause i use the directive 2> log.log & on
> the call of system.
> Example:
> system("php myscript.php 2> log.log &");
> This why IE will not wait until the script is finish...
>
> One thing i can't understand is why this child process of the apache
> user is not killed when i restart apache... that's the real deal...
>
> thanks
>
This doesn't actually start a new process of PHP seperate from Apache. What you are doing is
starting a child process of the child process or the root process of Apache.
What you might want to look in to is http://us2.php.net/manual/en/ref.pcntl.php
This will help you fork your processes, but I think you are still going to run into the same problem
even if you fork it within the php process of apache.
What you are probably going to need to do is create your own custom script that will act as a
daemon, and replace apache altogether.
This way it is completely separate from apache. It can run on its own port and only answer to you.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
Jim, i've already look for pcntl... but the support server guys, tell me
that they can't install php modules that are not pre-compiled... so,
pcntl is not an alternative...
I think you are right... i have to make this script a daemon... but how
can i do that with php??... the problem is that this daemon should be
started in web interface... see the problem...???
thanks
Jim Lucas escreveu:
> Rodolfo De Nadai wrote:
>> Edward , my best guess is that not IE is holding the connection but
>> the apache user... because the process is related to the apache
>> user... and there's more i can close IE, bacause i use the directive
>> 2> log.log & on the call of system.
>> Example:
>> system("php myscript.php 2> log.log &");
>> This why IE will not wait until the script is finish...
>>
>> One thing i can't understand is why this child process of the apache
>> user is not killed when i restart apache... that's the real deal...
>>
>> thanks
>>
>
> This doesn't actually start a new process of PHP seperate from
> Apache. What you are doing is starting a child process of the child
> process or the root process of Apache.
>
> What you might want to look in to is
> http://us2.php.net/manual/en/ref.pcntl.php
>
> This will help you fork your processes, but I think you are still
> going to run into the same problem even if you fork it within the php
> process of apache.
>
> What you are probably going to need to do is create your own custom
> script that will act as a daemon, and replace apache altogether.
>
> This way it is completely separate from apache. It can run on its own
> port and only answer to you.
>
--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *
*Informtica de Municpios Associados S.A.*
Seu governo mais inteligente
rodolfo.denadai
ima.sp.gov.br <mailto:rodolfo.denadai
ima.sp.gov.br> -
www.ima.sp.gov.br <http://www.ima.sp.gov.br/>
Fone: (19) 3739-6000 / Ramal: 1307
attached mail follows:
Rodolfo De Nadai wrote:
> Jim, i've already look for pcntl... but the support server guys, tell me
> that they can't install php modules that are not pre-compiled... so,
> pcntl is not an alternative...
>
Bummer, get new support server guys... no, but really....
> I think you are right... i have to make this script a daemon... but how
> can i do that with php??... the problem is that this daemon should be
> started in web interface... see the problem...???
Well, both windows and *nix have ways of running different apps as a daemon.
I actually wrote a little daemon that listens for UDP connections on a given port and takes care of
all incoming connections.
What do you mean "should be started in web interface" ? Does this mean that it should only be
running when you connect to it with a web browser?
>
> thanks
np
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
No... it not should only run when i'm connected to it throught a web
server...
it means that when i go to specific IE page and press a button named
'Enable' the daemon should be called and start to run indefinitly, and
i'm able to close IE session and the daemon keep working as well...
That's what i mean...
Jim Lucas escreveu:
> Rodolfo De Nadai wrote:
>> Jim, i've already look for pcntl... but the support server guys, tell
>> me that they can't install php modules that are not pre-compiled...
>> so, pcntl is not an alternative...
>>
>
> Bummer, get new support server guys... no, but really....
>
>> I think you are right... i have to make this script a daemon... but
>> how can i do that with php??... the problem is that this daemon
>> should be started in web interface... see the problem...???
>
> Well, both windows and *nix have ways of running different apps as a
> daemon.
>
> I actually wrote a little daemon that listens for UDP connections on a
> given port and takes care of all incoming connections.
>
> What do you mean "should be started in web interface" ? Does this
> mean that it should only be running when you connect to it with a web
> browser?
>
>>
>> thanks
>
> np
>
--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *
*Informtica de Municpios Associados S.A.*
Seu governo mais inteligente
rodolfo.denadai
ima.sp.gov.br <mailto:rodolfo.denadai
ima.sp.gov.br> -
www.ima.sp.gov.br <http://www.ima.sp.gov.br/>
Fone: (19) 3739-6000 / Ramal: 1307
attached mail follows:
Rodolfo De Nadai wrote:
> No... it not should only run when i'm connected to it throught a web
> server...
> it means that when i go to specific IE page and press a button named
> 'Enable' the daemon should be called and start to run indefinitly, and
> i'm able to close IE session and the daemon keep working as well...
>
> That's what i mean...
Well, in that case, what you could do is have a cron job, or if on windows some form of scheduled
task, that looks for a file that indicates that it should be running.
Then from apache, you could setup a page that has your enable button. When submitted, it creates a
file that indicates to the above scheduled task that it needs to run.
Then, when that scheduled task starts, it looks at the file and sees that it needs to be running,
then it stays running. It checks to see if it has a pid file already created. if it cannot find a
pid file, it creates a pid file to indicate that it is running. It checks every once in a while to
see if the file that tells it that it needs to be running it still there, once that file goes away,
it kills the pid file and kills itself too.
Then the scheduled jobs keeps checking...
You might find that you need to do a little refinement to this process. But, this is where I would
start.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
Right on the moment this process is not a option... because the project
should end in 4 weeks... perhaps after a while i could try use this
ideia of yours...
But right now i have to find a diferent solution...
But thanks Jim... that open new horizons...
Jim Lucas escreveu:
> Rodolfo De Nadai wrote:
>> No... it not should only run when i'm connected to it throught a web
>> server...
>> it means that when i go to specific IE page and press a button named
>> 'Enable' the daemon should be called and start to run indefinitly,
>> and i'm able to close IE session and the daemon keep working as well...
>>
>> That's what i mean...
>
> Well, in that case, what you could do is have a cron job, or if on
> windows some form of scheduled task, that looks for a file that
> indicates that it should be running.
>
> Then from apache, you could setup a page that has your enable button.
> When submitted, it creates a file that indicates to the above
> scheduled task that it needs to run.
>
> Then, when that scheduled task starts, it looks at the file and sees
> that it needs to be running, then it stays running. It checks to see
> if it has a pid file already created. if it cannot find a pid file, it
> creates a pid file to indicate that it is running. It checks every
> once in a while to see if the file that tells it that it needs to be
> running it still there, once that file goes away, it kills the pid
> file and kills itself too.
>
> Then the scheduled jobs keeps checking...
>
> You might find that you need to do a little refinement to this
> process. But, this is where I would start.
>
>
--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *
*Informtica de Municpios Associados S.A.*
Seu governo mais inteligente
rodolfo.denadai
ima.sp.gov.br <mailto:rodolfo.denadai
ima.sp.gov.br> -
www.ima.sp.gov.br <http://www.ima.sp.gov.br/>
Fone: (19) 3739-6000 / Ramal: 1307
attached mail follows:
> -----Original Message-----
> From: Rodolfo De Nadai [mailto:rodolfo.denadai
ima.sp.gov.br]
> Sent: Monday, September 17, 2007 5:25 AM
> To: php-general
lists.php.net
> Subject: [PHP] Try to find a solution, when restart Apache
> with PHP Script
>
> Hi all...
>
> I'm facing a serious problem with my application. I have a
> script write
> in PHP that starts in Internet Explorer, this script keep on running
> until a varible value change on my MySQL database.
> The problem is that when i restart Apache, the process child
> initalized
> isn't kill... then the apache can't be start because the script is use
> the port 80.
>
> To solve my problem, without change anything, the best would be that
> when i execute the script, it run on other port than the default 80...
> so this way apache could start...
> The is a way to redirect through php, so the script run on a diferent
> port?? Like change some line, or add on php.ini files?? or even in
> programming??
>
> thanks ... for any info
We do something like this, wherein sometimes we have to force a restart of
Apache, so in order to not kill the web page for the GUI, we use AJAX to
continually poll the server. Then when the server is back, we can issue a
page refresh to whatever page we want...
---------------------------8< snip
>8----------------------------------------
<?php
$request_interval = 10000; // 10 seconds.
$type = intval( $_GET[ 'type' ] );
if ( 1 == $type )
{
$initial_wait = 60000; // 1 minute.
$title = translate('Rebooting Appliance');
$text = translate('This may take several minutes. If this
page does not redirect you, click <A HREF="home_start_main.php">here</A>.');
}
else
{
$initial_wait = 20000; // 20 seconds.
$title = translate('Rebuilding Web Certificates');
$text = translate('If this page does not redirect you in a
few seconds, click <A HREF="home_start_main.php">here</A>.');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE><?= translate('%1$s :: Loading...', PRODUCT_fENF) ?></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;">
<LINK REL="STYLESHEET" TYPE="text/css"
HREF="includes/default.css?version=1">
</HEAD>
<BODY>
<TABLE WIDTH="100%" HEIGHT="100%">
<TR>
<TD ALIGN="center" VALIGN="middle" HEIGHT="100%"
WIDTH="100%">
<TABLE BORDER="0" CLASS="componentBox">
<TR VALIGN="middle">
<TD COLSPAN="3"
CLASS="tableHeadline"><?=$title?></TD>
</TR>
<TR VALIGN="MIDDLE">
<TD><IMG
SRC="images/icons/paper_time.gif"></TD>
<TD>
<TABLE>
<TR>
<TD><?=$text?></TD>
</TR>
<TR>
<TD
ALIGN="CENTER"><DIV ID="status" STYLE="color:gray"><?=
translate('Waiting...') ?></DIV></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var xmlhttp=false;
var id, state = 0;
var initial_wait = <?=$initial_wait?>;
// JScript gives us Conditional compilation, we can cope
with old IE versions.
// and security blocked creation of the objects.
try
{
xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP" );
}
catch ( e )
{
try
{
xmlhttp = new ActiveXObject(
"Microsoft.XMLHTTP" );
}
catch ( E )
{
xmlhttp = false;
}
}
if ( !xmlhttp && typeof XMLHttpRequest != 'undefined' )
{
xmlhttp = new XMLHttpRequest();
}
function try_url()
{
if ( 0 == state )
{
document.getElementById( "status"
).innerHTML = "<?= translate('Requesting page...') ?>";
xmlhttp.open( "HEAD", "home_start_main.php",
true );
xmlhttp.onreadystatechange=function()
{
state = xmlhttp.readyState
if ( 4 == state )
{
// Needed this try/catch
block for Firefox.
var httpstatus;
try
{
httpstatus =
xmlhttp.status;
}
catch ( e )
{
httpstatus = -1;
}
if( ( httpstatus == 200 ) ||
( httpstatus == null ) || ( httpstatus == 0 ) || ( httpstatus == 304 ) )
{
state = 0;
document.getElementById( "status" ).innerHTML = "<?= translate('Request
succeeded...') ?>";
self.clearInterval(
id );
document.location =
'home_start_main.php';
}
else
{
document.getElementById( "status" ).innerHTML = "<?= translate('Request
failed...') ?>";
state = 0;
}
}
}
xmlhttp.send( null )
}
}
function start_polling()
{
initial_wait = initial_wait - 1000;
if ( initial_wait <= 0 )
{
self.clearInterval( id );
document.getElementById( "status"
).innerHTML = "<?= translate('Requesting page...') ?>";
try_url();
id = self.setInterval( 'try_url()',
<?=$request_interval?> );
}
else
{
document.getElementById( "status"
).innerHTML = "<?= translate('Waiting ') ?>" + ( initial_wait / 1000 ) +
"...";
}
}
id = self.setInterval( 'start_polling()', 1000 );
//-->
</SCRIPT>
</BODY>
</HTML>
attached mail follows:
Hi Daevid,
This app keep alive forever as well?
When you restart apache what happend to your app?
Daevid Vincent escreveu:
>
>
>
>> -----Original Message-----
>> From: Rodolfo De Nadai [mailto:rodolfo.denadai
ima.sp.gov.br]
>> Sent: Monday, September 17, 2007 5:25 AM
>> To: php-general
lists.php.net
>> Subject: [PHP] Try to find a solution, when restart Apache
>> with PHP Script
>>
>> Hi all...
>>
>> I'm facing a serious problem with my application. I have a
>> script write
>> in PHP that starts in Internet Explorer, this script keep on running
>> until a varible value change on my MySQL database.
>> The problem is that when i restart Apache, the process child
>> initalized
>> isn't kill... then the apache can't be start because the script is use
>> the port 80.
>>
>> To solve my problem, without change anything, the best would be that
>> when i execute the script, it run on other port than the default 80...
>> so this way apache could start...
>> The is a way to redirect through php, so the script run on a diferent
>> port?? Like change some line, or add on php.ini files?? or even in
>> programming??
>>
>> thanks ... for any info
>>
>
> We do something like this, wherein sometimes we have to force a restart of
> Apache, so in order to not kill the web page for the GUI, we use AJAX to
> continually poll the server. Then when the server is back, we can issue a
> page refresh to whatever page we want...
>
>
> ---------------------------8< snip
>
>> 8----------------------------------------
>>
>
> <?php
> $request_interval = 10000; // 10 seconds.
> $type = intval( $_GET[ 'type' ] );
> if ( 1 == $type )
> {
> $initial_wait = 60000; // 1 minute.
> $title = translate('Rebooting Appliance');
> $text = translate('This may take several minutes. If this
> page does not redirect you, click <A HREF="home_start_main.php">here</A>.');
> }
> else
> {
> $initial_wait = 20000; // 20 seconds.
> $title = translate('Rebuilding Web Certificates');
> $text = translate('If this page does not redirect you in a
> few seconds, click <A HREF="home_start_main.php">here</A>.');
> }
> ?>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <HTML>
> <HEAD>
> <TITLE><?= translate('%1$s :: Loading...', PRODUCT_fENF) ?></TITLE>
> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;">
> <LINK REL="STYLESHEET" TYPE="text/css"
> HREF="includes/default.css?version=1">
> </HEAD>
> <BODY>
> <TABLE WIDTH="100%" HEIGHT="100%">
> <TR>
> <TD ALIGN="center" VALIGN="middle" HEIGHT="100%"
> WIDTH="100%">
> <TABLE BORDER="0" CLASS="componentBox">
> <TR VALIGN="middle">
> <TD COLSPAN="3"
> CLASS="tableHeadline"><?=$title?></TD>
> </TR>
> <TR VALIGN="MIDDLE">
> <TD><IMG
> SRC="images/icons/paper_time.gif"></TD>
> <TD>
> <TABLE>
> <TR>
>
> <TD><?=$text?></TD>
> </TR>
> <TR>
> <TD
> ALIGN="CENTER"><DIV ID="status" STYLE="color:gray"><?=
> translate('Waiting...') ?></DIV></TD>
> </TR>
> </TABLE>
> </TD>
> </TR>
> </TABLE>
> </TD>
> </TR>
> </TABLE>
> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
> <!--
> var xmlhttp=false;
> var id, state = 0;
> var initial_wait = <?=$initial_wait?>;
>
> // JScript gives us Conditional compilation, we can cope
> with old IE versions.
> // and security blocked creation of the objects.
> try
> {
> xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP" );
> }
> catch ( e )
> {
> try
> {
> xmlhttp = new ActiveXObject(
> "Microsoft.XMLHTTP" );
> }
> catch ( E )
> {
> xmlhttp = false;
> }
> }
> if ( !xmlhttp && typeof XMLHttpRequest != 'undefined' )
> {
> xmlhttp = new XMLHttpRequest();
> }
>
> function try_url()
> {
> if ( 0 == state )
> {
> document.getElementById( "status"
> ).innerHTML = "<?= translate('Requesting page...') ?>";
> xmlhttp.open( "HEAD", "home_start_main.php",
> true );
> xmlhttp.onreadystatechange=function()
> {
> state = xmlhttp.readyState
> if ( 4 == state )
> {
> // Needed this try/catch
> block for Firefox.
> var httpstatus;
> try
> {
> httpstatus =
> xmlhttp.status;
> }
> catch ( e )
> {
> httpstatus = -1;
> }
> if( ( httpstatus == 200 ) ||
> ( httpstatus == null ) || ( httpstatus == 0 ) || ( httpstatus == 304 ) )
> {
> state = 0;
>
> document.getElementById( "status" ).innerHTML = "<?= translate('Request
> succeeded...') ?>";
> self.clearInterval(
> id );
> document.location =
> 'home_start_main.php';
> }
> else
> {
>
> document.getElementById( "status" ).innerHTML = "<?= translate('Request
> failed...') ?>";
> state = 0;
> }
> }
> }
> xmlhttp.send( null )
> }
> }
>
> function start_polling()
> {
> initial_wait = initial_wait - 1000;
> if ( initial_wait <= 0 )
> {
> self.clearInterval( id );
> document.getElementById( "status"
> ).innerHTML = "<?= translate('Requesting page...') ?>";
> try_url();
> id = self.setInterval( 'try_url()',
> <?=$request_interval?> );
> }
> else
> {
> document.getElementById( "status"
> ).innerHTML = "<?= translate('Waiting ') ?>" + ( initial_wait / 1000 ) +
> "...";
> }
> }
>
> id = self.setInterval( 'start_polling()', 1000 );
> //-->
> </SCRIPT>
> </BODY>
> </HTML>
>
>
--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *
*Informtica de Municpios Associados S.A.*
Seu governo mais inteligente
rodolfo.denadai
ima.sp.gov.br <mailto:rodolfo.denadai
ima.sp.gov.br> -
www.ima.sp.gov.br <http://www.ima.sp.gov.br/>
Fone: (19) 3739-6000 / Ramal: 1307
attached mail follows:
We put a timeout at the top and show an error if the server never comes
back. You could do whatever you want. As long as the user doesn't try to
refresh the page or go somewhere else on your server, the ajax will just
keep trying in the background. That's all client-side JS / AJAX.
> -----Original Message-----
> From: Rodolfo De Nadai [mailto:rodolfo.denadai
ima.sp.gov.br]
> Sent: Monday, September 17, 2007 1:00 PM
> To: Daevid Vincent
> Cc: php-general
lists.php.net
> Subject: Re: [PHP] Try to find a solution, when restart
> Apache with PHP Script
>
> Hi Daevid,
> This app keep alive forever as well?
> When you restart apache what happend to your app?
>
> Daevid Vincent escreveu:
> >
> >
> >
> >> -----Original Message-----
> >> From: Rodolfo De Nadai [mailto:rodolfo.denadai
ima.sp.gov.br]
> >> Sent: Monday, September 17, 2007 5:25 AM
> >> To: php-general
lists.php.net
> >> Subject: [PHP] Try to find a solution, when restart Apache
> >> with PHP Script
> >>
> >> Hi all...
> >>
> >> I'm facing a serious problem with my application. I have a
> >> script write
> >> in PHP that starts in Internet Explorer, this script keep
> on running
> >> until a varible value change on my MySQL database.
> >> The problem is that when i restart Apache, the process child
> >> initalized
> >> isn't kill... then the apache can't be start because the
> script is use
> >> the port 80.
> >>
> >> To solve my problem, without change anything, the best
> would be that
> >> when i execute the script, it run on other port than the
> default 80...
> >> so this way apache could start...
> >> The is a way to redirect through php, so the script run on
> a diferent
> >> port?? Like change some line, or add on php.ini files?? or even in
> >> programming??
> >>
> >> thanks ... for any info
> >>
> >
> > We do something like this, wherein sometimes we have to
> force a restart of
> > Apache, so in order to not kill the web page for the GUI,
> we use AJAX to
> > continually poll the server. Then when the server is back,
> we can issue a
> > page refresh to whatever page we want...
> >
> >
> > ---------------------------8< snip
> >
> >> 8----------------------------------------
> >>
> >
> > <?php
> > $request_interval = 10000; // 10 seconds.
> > $type = intval( $_GET[ 'type' ] );
> > if ( 1 == $type )
> > {
> > $initial_wait = 60000; // 1 minute.
> > $title = translate('Rebooting Appliance');
> > $text = translate('This may take several
> minutes. If this
> > page does not redirect you, click <A
> HREF="home_start_main.php">here</A>.');
> > }
> > else
> > {
> > $initial_wait = 20000; // 20 seconds.
> > $title = translate('Rebuilding Web Certificates');
> > $text = translate('If this page does not
> redirect you in a
> > few seconds, click <A HREF="home_start_main.php">here</A>.');
> > }
> > ?>
> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> > <HTML>
> > <HEAD>
> > <TITLE><?= translate('%1$s :: Loading...',
> PRODUCT_fENF) ?></TITLE>
> > <META HTTP-EQUIV="Content-Type" CONTENT="text/html;">
> > <LINK REL="STYLESHEET" TYPE="text/css"
> > HREF="includes/default.css?version=1">
> > </HEAD>
> > <BODY>
> > <TABLE WIDTH="100%" HEIGHT="100%">
> > <TR>
> > <TD ALIGN="center" VALIGN="middle" HEIGHT="100%"
> > WIDTH="100%">
> > <TABLE BORDER="0" CLASS="componentBox">
> > <TR VALIGN="middle">
> > <TD COLSPAN="3"
> > CLASS="tableHeadline"><?=$title?></TD>
> > </TR>
> > <TR VALIGN="MIDDLE">
> > <TD><IMG
> > SRC="images/icons/paper_time.gif"></TD>
> > <TD>
> > <TABLE>
> > <TR>
> >
> > <TD><?=$text?></TD>
> > </TR>
> > <TR>
> >
> <TD
> > ALIGN="CENTER"><DIV ID="status" STYLE="color:gray"><?=
> > translate('Waiting...') ?></DIV></TD>
> > </TR>
> > </TABLE>
> > </TD>
> > </TR>
> > </TABLE>
> > </TD>
> > </TR>
> > </TABLE>
> > <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
> > <!--
> > var xmlhttp=false;
> > var id, state = 0;
> > var initial_wait = <?=$initial_wait?>;
> >
> > // JScript gives us Conditional compilation, we can cope
> > with old IE versions.
> > // and security blocked creation of the objects.
> > try
> > {
> > xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP" );
> > }
> > catch ( e )
> > {
> > try
> > {
> > xmlhttp = new ActiveXObject(
> > "Microsoft.XMLHTTP" );
> > }
> > catch ( E )
> > {
> > xmlhttp = false;
> > }
> > }
> > if ( !xmlhttp && typeof XMLHttpRequest != 'undefined' )
> > {
> > xmlhttp = new XMLHttpRequest();
> > }
> >
> > function try_url()
> > {
> > if ( 0 == state )
> > {
> > document.getElementById( "status"
> > ).innerHTML = "<?= translate('Requesting page...') ?>";
> > xmlhttp.open( "HEAD",
> "home_start_main.php",
> > true );
> > xmlhttp.onreadystatechange=function()
> > {
> > state = xmlhttp.readyState
> > if ( 4 == state )
> > {
> > // Needed this try/catch
> > block for Firefox.
> > var httpstatus;
> > try
> > {
> > httpstatus =
> > xmlhttp.status;
> > }
> > catch ( e )
> > {
> > httpstatus = -1;
> > }
> > if( (
> httpstatus == 200 ) ||
> > ( httpstatus == null ) || ( httpstatus == 0 ) || (
> httpstatus == 304 ) )
> > {
> > state = 0;
> >
> > document.getElementById( "status" ).innerHTML = "<?=
> translate('Request
> > succeeded...') ?>";
> >
> self.clearInterval(
> > id );
> >
> document.location =
> > 'home_start_main.php';
> > }
> > else
> > {
> >
> > document.getElementById( "status" ).innerHTML = "<?=
> translate('Request
> > failed...') ?>";
> > state = 0;
> > }
> > }
> > }
> > xmlhttp.send( null )
> > }
> > }
> >
> > function start_polling()
> > {
> > initial_wait = initial_wait - 1000;
> > if ( initial_wait <= 0 )
> > {
> > self.clearInterval( id );
> > document.getElementById( "status"
> > ).innerHTML = "<?= translate('Requesting page...') ?>";
> > try_url();
> > id = self.setInterval( 'try_url()',
> > <?=$request_interval?> );
> > }
> > else
> > {
> > document.getElementById( "status"
> > ).innerHTML = "<?= translate('Waiting ') ?>" + (
> initial_wait / 1000 ) +
> > "...";
> > }
> > }
> >
> > id = self.setInterval( 'start_polling()', 1000 );
> > //-->
> > </SCRIPT>
> > </BODY>
> > </HTML>
> >
> >
>
> --
> * Rodolfo De Nadai *
> * Analista de Sistema Jr. - Desenvolvimento *
>
>
>
>
> *Informtica de Municpios Associados S.A.*
> Seu governo mais inteligente
> rodolfo.denadai
ima.sp.gov.br
> <mailto:rodolfo.denadai
ima.sp.gov.br> -
> www.ima.sp.gov.br <http://www.ima.sp.gov.br/>
> Fone: (19) 3739-6000 / Ramal: 1307
>
>
attached mail follows:
Richard Kurth wrote:
>$Campaign_array| = array('0','1','3','5','8','15','25');|
>I know that I can find the next recored in a array using next. What
>I do not understand is if I know the last number was say 5 how do I
>tell the script that that is the current number so I can select the
>next record
What the next record?
Try:
$array = array('0','1','3','5','8','15','25');
$val = "5";
echo($array[array_search($val, $array)+1]);
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
tedd wrote:
> Richard Kurth wrote:
>
>> $Campaign_array| = array('0','1','3','5','8','15','25');|
>> I know that I can find the next recored in a array using next. What I
>> do not understand is if I know the last number was say 5 how do I tell
>> the script that that is the current number so I can select the next
>> record
>
>
> What the next record?
>
> Try:
>
> $array = array('0','1','3','5','8','15','25');
> $val = "5";
>
> echo($array[array_search($val, $array)+1]);
>
> Cheers,
>
> tedd
Not quite:
$array = array('0','1','3','5','8','15','25');
$val = "25";
echo($array[array_search($val, $array)+1]);
Notice: Undefined offset: 7 ...
brian
attached mail follows:
M. Sokolewicz wrote:
> Rick Pasotto wrote:
>> On Sun, Sep 16, 2007 at 06:04:45PM -0700, Richard Kurth wrote:
>>> Richard Kurth wrote:
>>>> Rick Pasotto wrote:
>>>>> On Sun, Sep 16, 2007 at 07:09:02PM -0400, brian wrote:
>>>>>
>>>>>> Richard Kurth wrote:
>>>>>>
>>>>>>> $Campaign_array| = array('0','1','3','5','8','15','25');|
>>>>>>> I know that I can find the next recored in a array using next.
>>>>>>> What I do not understand is if I know the last number was say 5
>>>>>>> how do I tell the script that that is the current number so I
>>>>>>> can select the next record
>>>>>>> ||
>>>>>>>
>>>>>> I think you'll need your own function for this.
>>>>>>
>>>>> Nope. Just use array_search().
>>>>>
>>>>> $k = array_search('5',$Campaign_array);
>>>>> if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k +
>>>>> 1]; }
>>>>>
>>>>>
>>>> I tried this and it gives me nothing back. It should give me a 8
>>>>
>>>> $Campaign_array= array('0','1','3','5','8','15','25');
>>>> $val="5";
>>>>
>>>> $k = array_search($val,$Campaign_array);
>>>> if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }
>>>>
>>> I figured out way it was not working $k + 1 > count needed to be
>>> $k + 1 < count
>>
>> Yup. Sorry 'bout that.
>>
>>> But now it works perfect
>>
>
> if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }
>
> is very over-the-top. What's wrong with
> if (isset($Campaign_array[$k+1]) { echo $Campaign_array[$k + 1]; }
>
> Not to mention I don't really like the whole way this has been
> handled, I'm sure there are better ways, but for this we'd need to
> know more about what you're doing and what you're trying to achieve,
> which we obviously don't.
What I am trying to is get all the days from a table where email
campaign = number. and then look at the last day that was sent and find
it in the list and get the next day that follows that day. At this point
the script below is not working. So if you have any Ideas that would be
a better way of doing this please let me know.
$query = "SELECT day FROM emailcampaign where campaign_id =
'$emailcampaign' AND member_id = '$members_id'";
$DB_Change_Campaign_Results = safe_query($query);
for ($i=0; $i < mysql_num_rows($DB_Change_Campaign_Results); $i++) {
$Change_Campaign_row = mysql_fetch_array($DB_Change_Campaign_Results);
$Campaign = $Change_Campaign_row['day'];
$Campaign_array[$Campaign] = $Change_Campaign_row;
}
$k = array_search($val,$Campaign_array);
if ($k + 1 < count($Campaign_array)){ echo $Campaign_array[$k + 1]; }
attached mail follows:
Richard Kurth wrote:
$query = " SELECT day
FROM emailcampaign
where campaign_id = '$emailcampaign'
AND member_id = '$members_id'
";
$DB_Change_Campaign_Results = safe_query($query);
while ( $row = mysql_fetch_array($DB_Change_Campaign_Results) ) {
$Campaign_array[$row['day']] = $row;
}
# At this point you have arrays as values for your $Campaign_array
# So, unless $k is an array that matches a sub array of $Campaign_array
# you're never going to get a match
$k = array_search($val,$Campaign_array);
# What is $k at this point? An int (1, 2, 3, etc...) , string (Sunday, Monday, etc...)
# Before I go any further I will need to know the above information.
if ( ($k + 1) < count($Campaign_array) ) {
echo $Campaign_array[$k + 1];
}
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
Jim Lucas wrote:
> Richard Kurth wrote:
>
>
> $query = " SELECT day
> FROM emailcampaign
> where campaign_id = '$emailcampaign'
> AND member_id = '$members_id'
> ";
> $DB_Change_Campaign_Results = safe_query($query);
>
> while ( $row = mysql_fetch_array($DB_Change_Campaign_Results) ) {
> $Campaign_array[$row['day']] = $row;
> }
>
> # At this point you have arrays as values for your $Campaign_array
> # So, unless $k is an array that matches a sub array of $Campaign_array
> # you're never going to get a match
>
> $k = array_search($val,$Campaign_array);
>
> # What is $k at this point? An int (1, 2, 3, etc...) , string
> (Sunday, Monday, etc...)
> # Before I go any further I will need to know the above information.
>
> if ( ($k + 1) < count($Campaign_array) ) {
> echo $Campaign_array[$k + 1];
> }
>
>
This is what I get if I run the above script.
From a var_dump($Campaign_array); I get
*array*
0 =>
*array*
0 => string '0' /(length=1)/
'day' => string '0' /(length=1)/
1 =>
*array*
0 => string '1' /(length=1)/
'day' => string '1' /(length=1)/
3 =>
*array*
0 => string '3' /(length=1)/
'day' => string '3' /(length=1)/
6 =>
*array*
0 => string '6' /(length=1)/
'day' => string '6' /(length=1)/
9 =>
*array*
0 => string '9' /(length=1)/
'day' => string '9' /(length=1)/
12 =>
*array*
0 => string '12' /(length=2)/
'day' => string '12' /(length=2)/
15 =>
*array*
0 => string '15' /(length=2)/
'day' => string '15' /(length=2)/
20 =>
*array*
0 => string '20' /(length=2)/
'day' => string '20' /(length=2)/
25 =>
*array*
0 => string '25' /(length=2)/
'day' => string '25' /(length=2)/
30 =>
*array*
0 => string '30' /(length=2)/
'day' => string '30' /(length=2)/
From a $val="5";
$k = array_search($val,$Campaign_array);
var_dump($k); I get
boolean false
attached mail follows:
REVISED
Try this
<?php
$query = " SELECT day
FROM emailcampaign
WHERE campaign_id = '$emailcampaign'
AND member_id = '$members_id'
";
$DB_Change_Campaign_Results = safe_query($query);
##
## NOTICE: changed from array to assoc
##
$Campaign_array = array();
while ( $row = mysql_fetch_assoc($DB_Change_Campaign_Results) ) {
## Switched to an indexed array with the day as the value instead of the key
$Campaign_array[] = $row['day'];
}
# At this point you have arrays as values for your $Campaign_array
# So, unless $k is an array that matches a sub array of $Campaign_array
# you're never going to get a match
$k = array_search($val,$Campaign_array);
# What is $k at this point? An int (1, 2, 3, etc...) , string (Sunday, Monday, etc...)
# Before I go any further I will need to know the above information.
if ( isset($Campaign_array[($k + 1)])) {
echo $Campaign_array[($k + 1)];
} else {
echo 'Not found';
}
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
Richard Kurth wrote:
>
> What I am trying to is get all the days from a table where email
> campaign = number. and then look at the last day that was sent and find
> it in the list and get the next day that follows that day. At this point
> the script below is not working. So if you have any Ideas that would be
> a better way of doing this please let me know.
>
>
> $query = "SELECT day FROM emailcampaign where campaign_id =
> '$emailcampaign' AND member_id = '$members_id'";
> $DB_Change_Campaign_Results = safe_query($query);
> for ($i=0; $i < mysql_num_rows($DB_Change_Campaign_Results); $i++) {
> $Change_Campaign_row = mysql_fetch_array($DB_Change_Campaign_Results);
> $Campaign = $Change_Campaign_row['day'];
> $Campaign_array[$Campaign] = $Change_Campaign_row;
> }
> $k = array_search($val,$Campaign_array);
> if ($k + 1 < count($Campaign_array)){ echo $Campaign_array[$k + 1]; }
>
You can simplify this greatly:
$Campaign_array = Array();
$DB_Change_Campaign_Results = safe_query($query);
while ($row = mysql_fetch_array($DB_Change_Campaign_Results))
{
array_push($Campaign_array, $row['day']);
}
Because you're only selecting day from the table, your row data consists
of only one column. You're repeating stuff unnecessarily by doing this:
$Campaign = $Change_Campaign_row['day'];
$Campaign_array[$Campaign] = $Change_Campaign_row;
IOW, for the row that contains '5', you'd end up with $Campaign_array[5]
== an array that essentially just points to the value '5'.
I also noticed that your dump shows that the days begin with 0. If these
are calendar days you're adding a further layer of complexity.
brian
attached mail follows:
Jim Lucas wrote:
> REVISED
>
> Try this
>
> <?php
>
> $query = " SELECT day
> FROM emailcampaign
> WHERE campaign_id = '$emailcampaign'
> AND member_id = '$members_id'
> ";
>
> $DB_Change_Campaign_Results = safe_query($query);
>
> ##
> ## NOTICE: changed from array to assoc
> ##
> $Campaign_array = array();
> while ( $row = mysql_fetch_assoc($DB_Change_Campaign_Results) ) {
> ## Switched to an indexed array with the day as the value instead of
> the key
> $Campaign_array[] = $row['day'];
> }
>
> # At this point you have arrays as values for your $Campaign_array
> # So, unless $k is an array that matches a sub array of $Campaign_array
> # you're never going to get a match
>
> $k = array_search($val,$Campaign_array);
>
> # What is $k at this point? An int (1, 2, 3, etc...) , string
> (Sunday, Monday, etc...)
> # Before I go any further I will need to know the above information.
> if ( isset($Campaign_array[($k + 1)])) {
> echo $Campaign_array[($k + 1)];
> } else {
> echo 'Not found';
> }
>
>
include ("includes/location.php");
$query = " SELECT day
FROM emailcampaign
where campaign_id = '1'
AND member_id = '8'
";
$DB_Change_Campaign_Results = safe_query($query);
$Campaign_array = array();
while ( $row = mysql_fetch_assoc($DB_Change_Campaign_Results) ) {
$Campaign_array[] = $row['day'];
}
if ( isset($Campaign_array[($k + 1)])) {
echo $Campaign_array[($k + 1)];
} else {
echo 'Not found';
}
var_dump($Campaign_array);
This is what I get now when I run this
1
*array*
0 => string '0' /(length=1)/
1 => string '1' /(length=1)/
2 => string '3' /(length=1)/
3 => string '6' /(length=1)/
4 => string '9' /(length=1)/
5 => string '12' /(length=2)/
6 => string '15' /(length=2)/
7 => string '20' /(length=2)/
8 => string '25' /(length=2)/
9 => string '30' /(length=2)/
attached mail follows:
brian wrote:
> Richard Kurth wrote:
>>
>> What I am trying to is get all the days from a table where email
>> campaign = number. and then look at the last day that was sent and
>> find it in the list and get the next day that follows that day. At
>> this point the script below is not working. So if you have any Ideas
>> that would be a better way of doing this please let me know.
>>
>>
>> $query = "SELECT day FROM emailcampaign where campaign_id =
>> '$emailcampaign' AND member_id = '$members_id'";
>> $DB_Change_Campaign_Results = safe_query($query);
>> for ($i=0; $i < mysql_num_rows($DB_Change_Campaign_Results); $i++) {
>> $Change_Campaign_row = mysql_fetch_array($DB_Change_Campaign_Results);
>> $Campaign = $Change_Campaign_row['day'];
>> $Campaign_array[$Campaign] = $Change_Campaign_row;
>> }
>> $k = array_search($val,$Campaign_array);
>> if ($k + 1 < count($Campaign_array)){ echo $Campaign_array[$k + 1]; }
>>
>
>
> You can simplify this greatly:
>
> $Campaign_array = Array();
>
> $DB_Change_Campaign_Results = safe_query($query);
>
> while ($row = mysql_fetch_array($DB_Change_Campaign_Results))
> {
> array_push($Campaign_array, $row['day']);
> }
>
> Because you're only selecting day from the table, your row data
> consists of only one column. You're repeating stuff unnecessarily by
> doing this:
>
> $Campaign = $Change_Campaign_row['day'];
> $Campaign_array[$Campaign] = $Change_Campaign_row;
>
> IOW, for the row that contains '5', you'd end up with
> $Campaign_array[5] == an array that essentially just points to the
> value '5'.
>
> I also noticed that your dump shows that the days begin with 0. If
> these are calendar days you're adding a further layer of complexity.
>
0 represents the email campain to send 0 mens send the one that gois out
the day the campain starts. the next number in the list is the next day
a email is sent out would represent 5 day after the starting day
attached mail follows:
Richard Kurth wrote:
> include ("includes/location.php");
> $query = " SELECT day
> FROM emailcampaign
> where campaign_id = '1'
> AND member_id = '8'
> ";
> $DB_Change_Campaign_Results = safe_query($query);
> $Campaign_array = array();
> while ( $row = mysql_fetch_assoc($DB_Change_Campaign_Results) ) {
> $Campaign_array[] = $row['day'];
> }
> if ( isset($Campaign_array[($k + 1)])) {
> echo $Campaign_array[($k + 1)];
> } else {
> echo 'Not found';
> }
> var_dump($Campaign_array);
>
>
> This is what I get now when I run this
>
> 1
>
> *array*
> 0 => string '0' /(length=1)/
> 1 => string '1' /(length=1)/
> 2 => string '3' /(length=1)/
> 3 => string '6' /(length=1)/
> 4 => string '9' /(length=1)/
> 5 => string '12' /(length=2)/
> 6 => string '15' /(length=2)/
> 7 => string '20' /(length=2)/
> 8 => string '25' /(length=2)/
> 9 => string '30' /(length=2)/
>
>
>
Are there going to be wholes in the date range?
if so, you will have to do that last bit like this.
<?php
include ("includes/location.php");
#
# Setting $k
# Make sure that $k is an integer, not a string.
# hence, no quotes
$k = 5;
$query = " SELECT day
FROM emailcampaign
WHERE campaign_id = '1'
AND member_id = '8'
";
$DB_Change_Campaign_Results = safe_query($query);
$Campaign_array = array();
while ( $row = mysql_fetch_assoc($DB_Change_Campaign_Results) ) {
$Campaign_array[] = $row['day'];
}
sort($Campaign_array);
foreach ( $Campaign_array AS $day ) {
if ( $day <= $k ) {
$day = next($Campaign_array);
break;
}
}
echo $day;
var_dump($Campaign_array);
?>
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
Richard Kurth wrote:
> What I am trying to is get all the days from a table where email
> campaign = number. and then look at the last day that was sent and find
> it in the list and get the next day that follows that day. At this point
> the script below is not working. So if you have any Ideas that would be
> a better way of doing this please let me know.
>
>
> $query = "SELECT day FROM emailcampaign where campaign_id =
> '$emailcampaign' AND member_id = '$members_id'";
> $DB_Change_Campaign_Results = safe_query($query);
> for ($i=0; $i < mysql_num_rows($DB_Change_Campaign_Results); $i++) {
> $Change_Campaign_row = mysql_fetch_array($DB_Change_Campaign_Results);
> $Campaign = $Change_Campaign_row['day'];
> $Campaign_array[$Campaign] = $Change_Campaign_row;
> }
> $k = array_search($val,$Campaign_array);
> if ($k + 1 < count($Campaign_array)){ echo $Campaign_array[$k + 1]; }
Ok, so just to recap (because I'm very confused now, even more after the
many tries on the list since):
You have table in your database called 'emailcampaign'. This table has a
column called 'day'.
Now, your table holds 1 row per "campaign" and the 'day' column
signifies when the last mail has been sent.
-- am I correct on this so far ? --
Next, you have an array which contains a FIXED collection of days on
which an email should be sent, which looks like so:
$days_to_send_email_on = array('0','1','3','5','8','15','25');
-- am I correct on this so far [2] ? --
You know the 'day' the last mail was sent, and you wish to check your
FIXED array to find out when the next email should be sent.
-- am I correct on this so far [3] ? --
If so, then there are a few things I'm wondering:
1. How did you come up with that fixed array? Is it the result of some
kind of calculation?
1.1 If so, it'd be easier to solve it the mathematical way.
1.2 If #1 is a "random" result (ie. user-input, or different), then
how about storing it in a table and doing:
SELECT day WHERE day > $last_day_it_was_sent_on ORDER BY day ASC LIMIT 1
2. Actually, that's all I'm wondering :)
- Tul
attached mail follows:
Hello,
I am a beginner in PHP. I need help with the function preg_replace.
I am trying to remove the backslashes ( \ ) from a string that is submitted
by the user.
It is submitted in a form but it adds \ before the quotation marks ( " ).
Will this change if I use the GET method instead of POST.
If not can you please tell me how to use preg_replace to remove the
backslashes.
Thank You,
Chaim Chaikin
Novice PHP programmer
Hotwire Band Website Administrator
http://hotwire.totalh.com
attached mail follows:
Chaim Chaikin wrote:
> Hello,
>
>
>
> I am a beginner in PHP. I need help with the function preg_replace.
>
> I am trying to remove the backslashes ( \ ) from a string that is submitted
> by the user.
>
> It is submitted in a form but it adds \ before the quotation marks ( " ).
>
> Will this change if I use the GET method instead of POST.
>
> If not can you please tell me how to use preg_replace to remove the
> backslashes.
>
Don't, use stripslashes() instead.
http://us.php.net/stripslashes
Here is a nice little hack that I use.
<plaintext><?php
print_r($_REQUEST);
function stripInput(&$ar) {
$ar = stripslashes($ar);
}
if ( get_magic_quotes_gpc() ) {
array_walk_recursive($_REQUEST, 'stripInput');
array_walk_recursive($_POST, 'stripInput');
array_walk_recursive($_GET, 'stripInput');
}
print_r($_REQUEST);
?>
you should see the difference
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
Jim Lucas wrote:
> Here is a nice little hack that I use.
>
"Little hack" it is, "nice" it isn't.
Ideally just turn off magic_quotes_gpc - you can do so in php.ini, or
perhaps your web server configuration files (httpd.conf, .htaccess etc.).
If you don't have access to any of the above then install the latest
version of PHP_Compat (http://pear.php.net/package/PHP_Compat) and
include 'PHP/Compat/Environment/magic_quotes_gpc_off.php'. Reversing the
effects of magic_quotes_gpc at runtime is far from trivial, there's lots
of potential for subtle bugs, let alone completely forgetting about
$_COOKIE.
If you're unable to install PHP_Compat, you can grab the relevant files
from CVS:
http://cvs.php.net/viewvc.cgi/pear/PHP_Compat/Compat/Environment/_magic_quotes_inputs.php?revision=1.3&view=markup
http://cvs.php.net/viewvc.cgi/pear/PHP_Compat/Compat/Environment/magic_quotes_gpc_off.php?revision=1.7&view=markup
Arpad
attached mail follows:
I've got a site (password protected, sorry) where I have this in the
top of my template:
session_start();
$iSessionId = session_id();
$iSessionName = session_name();
Then I have a bunch of links like this in the site:
echo "<a href=\"/departments/\">Departments</a>";
The first time, and only the first time you load the page, that link
is transformed in the HTML output to be this:
<a href="/departments/?
PHPSESSID=4aec641b497131493b1c4bf489def723">Departments</a>
But if I reload the page, or go to any other page, I will get this:
<a href="/departments/">Departments</a>
which is what I want. Obviously I could do something where if it
detects the PHPSESSID in the URL, it forces the page to reload, but I
was thinking that there would be another way to do this without
adding another page load into the mix. Is there?
--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326
P.S. Please note that my e-mail and website address have changed from
wncc.edu to wnc.edu.
attached mail follows:
Kevin Murphy wrote:
> I've got a site (password protected, sorry) where I have this in the top
> of my template:
>
> session_start();
> $iSessionId = session_id();