OSEC

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 5 May 2007 01:35:29 -0000 Issue 4773

php-general-digest-helplists.php.net
Date: Fri May 04 2007 - 20:35:29 CDT


php-general Digest 5 May 2007 01:35:29 -0000 Issue 4773

Topics (messages 254395 through 254451):

Re: Custom session save handler. What's happens really?
        254395 by: itoctopus
        254397 by: n.quirin.free.fr
        254445 by: Richard Lynch
        254446 by: Richard Lynch

Re: passing GET via include
        254396 by: Tijnema !
        254447 by: Richard Lynch

Using timezones
        254398 by: Rob Desbois
        254399 by: Tijnema !
        254409 by: Oliver Block

Limit query results
        254400 by: Dan Shirah
        254401 by: Fredrik Thunberg
        254402 by: Zoltán Németh
        254403 by: "Miguel J. Jiménez"
        254415 by: Jim Lucas

Re: multipart/form-data POST request with empty file part
        254404 by: Emmanuel Raulo-Kumagai
        254427 by: Brad Fuller

Re: File uploading and saving info on mysql
        254405 by: Marcelo Wolfgang

Selecting a special row from the database
        254406 by: Marcelo Wolfgang
        254408 by: Alister Bulman
        254411 by: Edward Kay
        254412 by: Edward Kay
        254413 by: Fredrik Thunberg
        254414 by: Edward Kay
        254424 by: Emmanuel Raulo-Kumagai
        254440 by: Richard Lynch
        254441 by: Richard Lynch

Problem with timeout
        254407 by: Frank Arensmeier
        254420 by: Emmanuel Raulo-Kumagai
        254430 by: Frank Arensmeier
        254435 by: Richard Lynch
        254438 by: Frank Arensmeier

Drawing all characters using GD
        254410 by: Seth Price
        254434 by: Richard Lynch
        254437 by: Seth Price
        254450 by: Crayon

Send binary files with gzip encoding disabled
        254416 by: strawks
        254422 by: Emmanuel Raulo-Kumagai
        254433 by: Richard Lynch

Re: Name Capitalization
        254417 by: Michelle Konzack
        254418 by: Michelle Konzack
        254419 by: Michelle Konzack
        254423 by: Paul Novitski
        254432 by: Richard Lynch

Re: PHP's ldap_sasl_bind tries to authenticate with KRB5CCNAME other than the one provided by mod_auth_kerb
        254421 by: javier.pb

Loop problem
        254425 by: Dan Shirah
        254426 by: Daniel Brown
        254428 by: Dan Shirah
        254429 by: Daniel Brown
        254431 by: Richard Lynch

A problem with passing $_GET in an url (problem solved)
        254436 by: Davis Chan

Getting multitple select values on PHP side
        254439 by: Skip Evans
        254442 by: Richard Lynch
        254443 by: Richard Lynch
        254449 by: Paul Novitski

Re: Why does this encoding work in PHP?
        254444 by: Richard Lynch

Re: A problem with passing $_GET in an url
        254448 by: Richard Lynch

parse error
        254451 by: Brad Sumrall

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


You have to explicitly serialize and unserialize the objects.
I think the confusion here is with the automatic __wakeup and __sleep
functions:
http://www.devshed.com/c/a/PHP/Using-the-Sleep-and-Wakeup-Functions-to-Serialize-Objects-in-PHP/

--
itoctopus - http://www.itoctopus.com
<n.quirinfree.fr> wrote in message
news:1178263604.463ae03437fd5imp.free.fr...
> Hi,
>
> i'm using in each script:
>
> <?
> session_set_save_handler(...); //register my custom function to store
> session
> //into a mysql database
>
> session_start(); //session.auto_start is set to 0 in php.ini
> register_shutdown("session_write_close");
>
> $object = unserialize($_SESSION['objectname']);
> //modify the object
> //....
> $_SESSION['objectname'] = serialize($object);
> ?>
>
> When are exactly called the write and read function of my custom handler?
> Is it at the session_start that read function is called?
> or is it at $object = unserialize($_SESSION['objectname'])?
>
> Is write function called at session_write_close only?
> or any time $_SESSION[] is writted?
>
> Thanks a lot, I have no clue from PHP tutorial about this...

attached mail follows:


Thanks, but I serialize and unserialize the objects and this is not my
problem...(I known best practices for php5 about object serialization).

Please read again the post.

Selon itoctopus <newsgroupitoctopus.com>:

> You have to explicitly serialize and unserialize the objects.
> I think the confusion here is with the automatic __wakeup and __sleep
> functions:
>
http://www.devshed.com/c/a/PHP/Using-the-Sleep-and-Wakeup-Functions-to-Serialize-Objects-in-PHP/
>
>
> --
> itoctopus - http://www.itoctopus.com
> <n.quirinfree.fr> wrote in message
> news:1178263604.463ae03437fd5imp.free.fr...
> > Hi,
> >
> > i'm using in each script:
> >
> > <?
> > session_set_save_handler(...); //register my custom function to store
> > session
> > //into a mysql database
> >
> > session_start(); //session.auto_start is set to 0 in php.ini
> > register_shutdown("session_write_close");
> >
> > $object = unserialize($_SESSION['objectname']);
> > //modify the object
> > //....
> > $_SESSION['objectname'] = serialize($object);
> > ?>
> >
> > When are exactly called the write and read function of my custom handler?
> > Is it at the session_start that read function is called?
> > or is it at $object = unserialize($_SESSION['objectname'])?
> >
> > Is write function called at session_write_close only?
> > or any time $_SESSION[] is writted?
> >
> > Thanks a lot, I have no clue from PHP tutorial about this...
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

attached mail follows:


On Fri, May 4, 2007 2:26 am, n.quirinfree.fr wrote:
> i'm using in each script:
>
> <?
> session_set_save_handler(...); //register my custom function to store
> session
> //into a mysql database
>
> session_start(); //session.auto_start is set to 0 in php.ini
> register_shutdown("session_write_close");
>
> $object = unserialize($_SESSION['objectname']);
> //modify the object
> //....
> $_SESSION['objectname'] = serialize($object);
> ?>
>
> When are exactly called the write and read function of my custom
> handler?
> Is it at the session_start that read function is called?

Probably.

> or is it at $object = unserialize($_SESSION['objectname'])?

Possibly.

Use http://php.net/error_log with a timestamp and find out...

> Is write function called at session_write_close only?

Almost for sure.

> or any time $_SESSION[] is writted?

That would be HORRIBLE performance, so probably NOT.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

attached mail follows:


On Fri, May 4, 2007 6:37 am, n.quirinfree.fr wrote:
> Thanks, but I serialize and unserialize the objects and this is not my
> problem...(I known best practices for php5 about object
> serialization).

I think they meant you do *NOT* have to serialize/unserialize, as PHP
is gonna do it for you in the guts of session code.

So basically PHP is gonna serialize your serialized data, and then
unserialize it, and then you unserialized that.

It will work, but it's a bit expensive for a large object, I should
think...

Or maybe not, as once you have it as a big long string, how long can
it take PHP to serialize that? Feh.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

attached mail follows:


On 5/4/07, Oliver Block <listsblock-online.eu> wrote:
> Am Freitag, 4. Mai 2007 09:22 schrieb Mark Smith:
> > Hello all,
> > Is there a way to allow the passing of variables to included scripts
>
> See it another way: The includED script will be part of the includING script.
>
> ---------------includeme.inc-----------------
> <?php
> $message="Hello!\n";
> ?>
> ---------------includer.php------------------
> <?php
> include('includeme.inc');
> echo $message;
> ?>
> -------------------------------------------------
>
> Will be the same as
> ---------------dont_like_inclusions.php-------------------
> <?php
> $message="Hello\n";
> echo $message;
> ?>
> ---------------------------------------------------------------
>
>
> Regards,
>
> Oliver

Actually, it will be this:
<?php
?>
<?php
       $message="Hello\n";
?>
<?php
       echo $message;
?>

As you could, for example, include a HTML document :)

Tijnema

attached mail follows:


On Fri, May 4, 2007 2:22 am, Mark Smith wrote:
> Is there a way to allow the passing of variables to included scripts
> using the GET method, for example include"file.php?name=person"; or is
> there another method of including files that allow you to do this. I
> have attempted to do this without success, I just get a message saying
> the file cannot be found.

Well, there's sort of a way to do that.

Don't do anything. :-)

The variable is already there, waiting for you to use it.

You may want to study up on "scope" however:
http://us.php.net/manual/en/language.variables.scope.php

If you are in a function, you need to pass $name to that function, or
you need to declare it "global" Passing it in is almost always
better.

If you just want the original $_GET data, raw and unfiltered, $_GET is
a "superglobal" and you can juse it anywhere, any time. (Ditto for
$_POST and all the others)

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

attached mail follows:


I have a script which uses UTC times read from a database.

Up until now the users have just provided their current timezone offset from UTC in hours, but this needs to be changed as the script may not be running on a server with UTC set and I'd like to use set_default_timezone().

Looking at the documentation, all of the timezones which I want to provide (Etc/GMT+N, Etc/GMT-N and UTC) are listed as 'only existing for backward compatible reasons'.
Is there any reason why UTC should exist only for backward compatible reasons?? It seems like a pretty important timezone to me...

What's the best way to go about providing this functionality? Should I just provide an option of all regional timezones (how do I use this? The manual says where to download a pre-compiled Windows DLL but doesn't explain how to use it). Even if I do that how should I obtain UTC time if UTC is a deprecated timezone?

Thanks!
Rob

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

attached mail follows:


On 5/4/07, Rob Desbois <robert.desboischronos.co.uk> wrote:
> I have a script which uses UTC times read from a database.
>
> Up until now the users have just provided their current timezone offset from UTC in hours, but this needs to be changed as the script may not be running on a server with UTC set and I'd like to use set_default_timezone().
>
> Looking at the documentation, all of the timezones which I want to provide (Etc/GMT+N, Etc/GMT-N and UTC) are listed as 'only existing for backward compatible reasons'.
> Is there any reason why UTC should exist only for backward compatible reasons?? It seems like a pretty important timezone to me...
>
> What's the best way to go about providing this functionality? Should I just provide an option of all regional timezones (how do I use this? The manual says where to download a pre-compiled Windows DLL but doesn't explain how to use it). Even if I do that how should I obtain UTC time if UTC is a deprecated timezone?
>
> Thanks!
> Rob

Quite strange that UTC and GMT are deprecated timezones..., anyway, if
you don't want to use them, use one of the cities that are in GMT
timezone (Europe/London for example). I don't know how this will
behave as London (and whole GB) uses DST, so that might have affect
the real time ...

Tijnema

attached mail follows:


Am Freitag, 4. Mai 2007 13:39 schrieb Rob Desbois:
> What's the best way to go about providing this functionality? Should I just
> provide an option of all regional timezones (how do I use this?

If the user specifies the timezone, it might be comfortable to use the time
zones as described in Appendix I.

<http://de.php.net/manual/de/timezones.php>

> The manual
> says where to download a pre-compiled Windows DLL but doesn't explain how
> to use it). Even if I do that how should I obtain UTC time if UTC is a
> deprecated timezone?

AFAIK the timezone data is builtin by default, so you would not need to
install anything else.

Regards,

Oliver

attached mail follows:


Good Morning everyone.

In the below code I am pulling records from two tables. the records are
tied together by a common key in a 3rd table. Everything works correctly
down to the $result.

 // Connect to the database
  $connection = mssql_pconnect($host, $user, $pass) or die ('server
connection failed');
  $database = mssql_select_db("$database", $connection) or die ('DB
selection failed');
  // Query the table and load all of the records into an array.
   $sql = "SELECT
     support_payment_request.credit_card_id,
     support_payment_request.status_code,
     criminal_payment_request.credit_card_id,
     criminal_payment_request.status_code,
     credit_card_payment_request.credit_card_id,
     credit_card_payment_request.date_request_received
    FROM
     credit_card_payment_request LEFT OUTER JOIN support_payment_request
    ON support_payment_request.credit_card_id =
credit_card_payment_request.credit_card_id
     LEFT OUTER JOIN criminal_payment_request
    ON criminal_payment_request.credit_card_id =
credit_card_payment_request.credit_card_id
    WHERE support_payment_request.status_code = 'P'
    OR criminal_payment_request.status_code = 'P'";

    // print_r ($sql);
  $result = mssql_query($sql) or die(mssql_error());
           // print_r ($result);
  $number_rows= mssql_num_rows($result);
?>
<table width='780' border='1' align='center' cellpadding='2' cellspacing='2'
bordercolor='#000000'>
<?php
if(!empty($result)) {
 while ($row= mssql_fetch_array($result)) {
  $id = $row['credit_card_id'];
  $dateTime = $row['date_request_received'];
  //print_r ($id);
?>
<tr>
<td width='88' height='13' align='center' class='tblcell'><div
align='center'><?php echo "<a href='javascript:editRecord($id)'>$id</a>"
?></div></td>
<td width='224' height='13' align='center' class='tblcell'><div
align='center'><?php echo "$dateTime" ?></div></td>
<td width='156' height='13' align='center' class='tblcell'><div
align='center'><?php echo "To Be Processed" ?></div></td>
<td width='156' height='13' align='center' class='tblcell'><div
align='center'><?php echo "Payment Type" ?></div></td>
<td width='156' height='13' align='center' class='tblcell'><div
align='center'><?php echo "Last Processed By" ?></div></td>
</tr>
<?php
 }
}
?>

The picture below is what mu output looks like. BUT, what I am trying to do
is have only ONE row returned per ID regardless of however many records may
be associated with that ID. Below record number 122 has three results, I
only want one row for record 122 to be displayed.

Any ideas?

   2 <javascript:editRecord(2)>
 Oct 6 2010 12:00AM
 To Be Processed
 Payment Type
 Last Processed By
 46 <javascript:editRecord(46)>
 Feb 23 2007 2:27PM
 To Be Processed
 Payment Type
 Last Processed By
 66 <javascript:editRecord(66)>
 Feb 26 2007 3:16PM
 To Be Processed
 Payment Type
 Last Processed By
 68 <javascript:editRecord(68)>
 Feb 26 2007 3:39PM
 To Be Processed
 Payment Type
 Last Processed By
 76 <javascript:editRecord(76)>
 Mar 21 2007 7:36AM
 To Be Processed
 Payment Type
 Last Processed By
 77 <javascript:editRecord(77)>
 Mar 21 2007 7:40AM
 To Be Processed
 Payment Type
 Last Processed By
 78 <javascript:editRecord(78)>
 Mar 21 2007 7:40AM
 To Be Processed
 Payment Type
 Last Processed By
 79 <javascript:editRecord(79)>
 Mar 21 2007 7:41AM
 To Be Processed
 Payment Type
 Last Processed By
 122 <javascript:editRecord(122)>
 Mar 27 2007 5:29PM
 To Be Processed
 Payment Type
 Last Processed By
 122 <javascript:editRecord(122)>
 Mar 27 2007 5:29PM
 To Be Processed
 Payment Type
 Last Processed By
 122 <javascript:editRecord(122)>
 Mar 27 2007 5:29PM
 To Be Processed
 Payment Type
 Last Processed By

attached mail follows:


"GROUP BY whatever_id_you_want" in the SQL

Dan Shirah skrev:
> Good Morning everyone.
>
> In the below code I am pulling records from two tables. the records are
> tied together by a common key in a 3rd table. Everything works correctly
> down to the $result.
>
>
> // Connect to the database
> $connection = mssql_pconnect($host, $user, $pass) or die ('server
> connection failed');
> $database = mssql_select_db("$database", $connection) or die ('DB
> selection failed');
> // Query the table and load all of the records into an array.
> $sql = "SELECT
> support_payment_request.credit_card_id,
> support_payment_request.status_code,
> criminal_payment_request.credit_card_id,
> criminal_payment_request.status_code,
> credit_card_payment_request.credit_card_id,
> credit_card_payment_request.date_request_received
> FROM
> credit_card_payment_request LEFT OUTER JOIN support_payment_request
> ON support_payment_request.credit_card_id =
> credit_card_payment_request.credit_card_id
> LEFT OUTER JOIN criminal_payment_request
> ON criminal_payment_request.credit_card_id =
> credit_card_payment_request.credit_card_id
> WHERE support_payment_request.status_code = 'P'
> OR criminal_payment_request.status_code = 'P'";
>
> // print_r ($sql);
> $result = mssql_query($sql) or die(mssql_error());
> // print_r ($result);
> $number_rows= mssql_num_rows($result);
> ?>
> <table width='780' border='1' align='center' cellpadding='2'
> cellspacing='2'
> bordercolor='#000000'>
> <?php
> if(!empty($result)) {
> while ($row= mssql_fetch_array($result)) {
> $id = $row['credit_card_id'];
> $dateTime = $row['date_request_received'];
> //print_r ($id);
> ?>
> <tr>
> <td width='88' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "<a href='javascript:editRecord($id)'>$id</a>"
> ?></div></td>
> <td width='224' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "$dateTime" ?></div></td>
> <td width='156' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "To Be Processed" ?></div></td>
> <td width='156' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "Payment Type" ?></div></td>
> <td width='156' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "Last Processed By" ?></div></td>
> </tr>
> <?php
> }
> }
> ?>
>
> The picture below is what mu output looks like. BUT, what I am trying
> to do
> is have only ONE row returned per ID regardless of however many records may
> be associated with that ID. Below record number 122 has three results, I
> only want one row for record 122 to be displayed.
>
> Any ideas?
>
>
> 2 <javascript:editRecord(2)>
> Oct 6 2010 12:00AM
> To Be Processed
> Payment Type
> Last Processed By
> 46 <javascript:editRecord(46)>
> Feb 23 2007 2:27PM
> To Be Processed
> Payment Type
> Last Processed By
> 66 <javascript:editRecord(66)>
> Feb 26 2007 3:16PM
> To Be Processed
> Payment Type
> Last Processed By
> 68 <javascript:editRecord(68)>
> Feb 26 2007 3:39PM
> To Be Processed
> Payment Type
> Last Processed By
> 76 <javascript:editRecord(76)>
> Mar 21 2007 7:36AM
> To Be Processed
> Payment Type
> Last Processed By
> 77 <javascript:editRecord(77)>
> Mar 21 2007 7:40AM
> To Be Processed
> Payment Type
> Last Processed By
> 78 <javascript:editRecord(78)>
> Mar 21 2007 7:40AM
> To Be Processed
> Payment Type
> Last Processed By
> 79 <javascript:editRecord(79)>
> Mar 21 2007 7:41AM
> To Be Processed
> Payment Type
> Last Processed By
> 122 <javascript:editRecord(122)>
> Mar 27 2007 5:29PM
> To Be Processed
> Payment Type
> Last Processed By
> 122 <javascript:editRecord(122)>
> Mar 27 2007 5:29PM
> To Be Processed
> Payment Type
> Last Processed By
> 122 <javascript:editRecord(122)>
> Mar 27 2007 5:29PM
> To Be Processed
> Payment Type
> Last Processed By
>

attached mail follows:


SELECT DISTINCT?

greets
Zoltán Németh

2007. 05. 4, péntek keltezéssel 08.44-kor Dan Shirah ezt írta:
> Good Morning everyone.
>
> In the below code I am pulling records from two tables. the records are
> tied together by a common key in a 3rd table. Everything works correctly
> down to the $result.
>
>
> // Connect to the database
> $connection = mssql_pconnect($host, $user, $pass) or die ('server
> connection failed');
> $database = mssql_select_db("$database", $connection) or die ('DB
> selection failed');
> // Query the table and load all of the records into an array.
> $sql = "SELECT
> support_payment_request.credit_card_id,
> support_payment_request.status_code,
> criminal_payment_request.credit_card_id,
> criminal_payment_request.status_code,
> credit_card_payment_request.credit_card_id,
> credit_card_payment_request.date_request_received
> FROM
> credit_card_payment_request LEFT OUTER JOIN support_payment_request
> ON support_payment_request.credit_card_id =
> credit_card_payment_request.credit_card_id
> LEFT OUTER JOIN criminal_payment_request
> ON criminal_payment_request.credit_card_id =
> credit_card_payment_request.credit_card_id
> WHERE support_payment_request.status_code = 'P'
> OR criminal_payment_request.status_code = 'P'";
>
> // print_r ($sql);
> $result = mssql_query($sql) or die(mssql_error());
> // print_r ($result);
> $number_rows= mssql_num_rows($result);
> ?>
> <table width='780' border='1' align='center' cellpadding='2' cellspacing='2'
> bordercolor='#000000'>
> <?php
> if(!empty($result)) {
> while ($row= mssql_fetch_array($result)) {
> $id = $row['credit_card_id'];
> $dateTime = $row['date_request_received'];
> //print_r ($id);
> ?>
> <tr>
> <td width='88' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "<a href='javascript:editRecord($id)'>$id</a>"
> ?></div></td>
> <td width='224' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "$dateTime" ?></div></td>
> <td width='156' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "To Be Processed" ?></div></td>
> <td width='156' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "Payment Type" ?></div></td>
> <td width='156' height='13' align='center' class='tblcell'><div
> align='center'><?php echo "Last Processed By" ?></div></td>
> </tr>
> <?php
> }
> }
> ?>
>
> The picture below is what mu output looks like. BUT, what I am trying to do
> is have only ONE row returned per ID regardless of however many records may
> be associated with that ID. Below record number 122 has three results, I
> only want one row for record 122 to be displayed.
>
> Any ideas?
>
>
> 2 <javascript:editRecord(2)>
> Oct 6 2010 12:00AM
> To Be Processed
> Payment Type
> Last Processed By
> 46 <javascript:editRecord(46)>
> Feb 23 2007 2:27PM
> To Be Processed
> Payment Type
> Last Processed By
> 66 <javascript:editRecord(66)>
> Feb 26 2007 3:16PM
> To Be Processed
> Payment Type
> Last Processed By
> 68 <javascript:editRecord(68)>
> Feb 26 2007 3:39PM
> To Be Processed
> Payment Type
> Last Processed By
> 76 <javascript:editRecord(76)>
> Mar 21 2007 7:36AM
> To Be Processed
> Payment Type
> Last Processed By
> 77 <javascript:editRecord(77)>
> Mar 21 2007 7:40AM
> To Be Processed
> Payment Type
> Last Processed By
> 78 <javascript:editRecord(78)>
> Mar 21 2007 7:40AM
> To Be Processed
> Payment Type
> Last Processed By
> 79 <javascript:editRecord(79)>
> Mar 21 2007 7:41AM
> To Be Processed
> Payment Type
> Last Processed By
> 122 <javascript:editRecord(122)>
> Mar 27 2007 5:29PM
> To Be Processed
> Payment Type
> Last Processed By
> 122 <javascript:editRecord(122)>
> Mar 27 2007 5:29PM
> To Be Processed
> Payment Type
> Last Processed By
> 122 <javascript:editRecord(122)>
> Mar 27 2007 5:29PM
> To Be Processed
> Payment Type
> Last Processed By

attached mail follows:


Use "SELECT DISTINCT" in your SQL syntax.

--
Miguel J. Jiménez
Programador Senior
Área de Internet/XSL/PHP
migueljose.jimenezisotrol.com

----------------------------------------------------

ISOTROL
Edificio BLUENET, Avda. Isaac Newton nº3, 4ª planta.
Parque Tecnológico Cartuja '93, 41092 Sevilla.
Teléfono: 955 036 800 - Fax: 955 036 849
http://www.isotrol.com

"You let a political fight come between you and your best friend you have in all the world. Do you realize how foolish that is? How ominous? How can this country survive if friends can't rise above the quarrel".
Constance Hazard, North & South (book I)

attached mail follows:


Dan Shirah wrote:
> $result = mssql_query($sql) or die(mssql_error());
> // print_r ($result);
You realize that this will print the Resource ID# for the resource pointer, but not the actual
result set.

--
Jim Lucas

    "Some men are born to greatness, some achieve greatness,
        and some have greatness thrust upon them."

Unknown

attached mail follows:


Hello

I'm writting a client in PHP for some CMS.
I need to send an HTTP POST request with a multipart/form-data content.
One of the parts is a file which must look like the request was issued
after submitting a web form with a <input type="file" ...> field left
empty, which is *NOT* the same as sending an empty file.
This means the part should look like this in the request:

-----------------------------8179530329826\r\n
Content-Disposition: form-data; name="file"; filename=""\r\n
Content-Type: application/octet-stream\r\n
\r\n
\r\n
-----------------------------8179530329826\r\n

Is there a way to do so with cURL ?
Thanks in advance

--
Emmanuel

attached mail follows:


Emmanuel Raulo-Kumagai wrote:
> Sent: Friday, May 04, 2007 8:44 AM
> To: php-generallists.php.net
> Subject: [PHP] cURL: multipart/form-data POST request with
> empty file part
>
> Hello
>
> I'm writting a client in PHP for some CMS.
> I need to send an HTTP POST request with a
> multipart/form-data content.
> One of the parts is a file which must look like the request
> was issued after submitting a web form with a <input
> type="file" ...> field left empty, which is *NOT* the same as
> sending an empty file.
> This means the part should look like this in the request:
>
> -----------------------------8179530329826\r\n
> Content-Disposition: form-data; name="file"; filename=""\r\n
> Content-Type: application/octet-stream\r\n \r\n \r\n
> -----------------------------8179530329826\r\n
>
> Is there a way to do so with cURL ?

Possibly. Search the web for CURLOPT_CUSTOMREQUEST.

If cURL won't do what you need, you can always send a custom HTTP POST
request using fsockopen(). Again, search the web for examples.

-B

attached mail follows:


Richard Lynch wrote:
>
> Browsers will probably NOT populate these reliably...
>
> Mac Safari, might, for example, choose "application/x-pdf" for the PDF
> file.
>
> You really can't rely on 'type' to be useful in any way, shape, or form.
>

Thanks for the tips, I've deleted this check, and changed how I check
for the file type in the code.

and I've redone the code to match Jim Lucas suggestion also, it's
working very nicely right now.

attached mail follows:


Hi all,

I'm building a news display page for a website, and since the user has 2
ways to arrive there, I want to know if this is possible:

1) the user arrive at news.php

I will run a query at the db, and get the latest news to be the main one
  (full display) and display the others news in a list

2) the user arrived from a link to a specific news to news.php?id=10

It should display the news with id = 10 as the main news and get the
latest ones to display in a list of other news

I've so far was able to add a dinamic WHERE to my query ( if I have or
not the id GET parameter ) and if I don't have it, I'm able to display
the latest result as the main news, but when I have an id as a GET
parameter, I have a where clause in my query and it will return only the
main news and not build up the news list

what I want is to separate the news that the user want to see ( the
id=XX one ) from the others rows, can someone advice me ?

Here is the code I have so far, I hope it serve as a better explanation
than mine!

<?
$newsId = $_GET['id'];
if (isset($newsID)){
        $whereClause = 'WHERE auto_id ='.$newsId;
} else {
        $whereClause = '';
}
mysql_connect("localhost",$user,$pass) or die (mysql_error());
mysql_select_db ($db_table);
$SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC";
$news_Query = mysql_query($SQL);
$recordCount = mysql_numrows($news_Query);
mysql_close();
?>

TIA
Marcelo Wolfgang

attached mail follows:


On 04/05/07, Marcelo Wolfgang <marcelow3ol.com.br> wrote:

> I'm building a news display page for a website, and since the user has 2
> ways to arrive there, I want to know if this is possible:
>
> 1) the user arrive at news.php
>
> I will run a query at the db, and get the latest news to be the main one
> (full display) and display the others news in a list
>
> 2) the user arrived from a link to a specific news to news.php?id=10
>
> It should display the news with id = 10 as the main news and get the
> latest ones to display in a list of other news

> Here is the code I have so far, I hope it serve as a better explanation
> than mine!

> <?
> $newsId = $_GET['id'];
> if (isset($newsID)){
> $whereClause = 'WHERE auto_id ='.$newsId;
> } else {
> $whereClause = '';
> }
> mysql_connect("localhost",$user,$pass) or die (mysql_error());
> mysql_select_db ($db_table);
> $SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC";

Yep, thats pretty classic.
One thing I would do - assuming $newsId should always be an integer

$whereClause = '';
if (isset($_GET['id']) {
  $newsId = intval($_GET['id']);
  if ($newsId) // if not 0
    $whereClause = 'WHERE auto_id ='.$newsId;
}
.....

Alister

attached mail follows:


> -----Original Message-----
> From: Marcelo Wolfgang [mailto:marcelow3ol.com.br]
> Sent: 04 May 2007 14:37
> To: php-generallists.php.net
> Subject: [PHP] Selecting a special row from the database
>
>
> Hi all,
>
> I'm building a news display page for a website, and since the user has 2
> ways to arrive there, I want to know if this is possible:
>
> 1) the user arrive at news.php
>
> I will run a query at the db, and get the latest news to be the main one
> (full display) and display the others news in a list
>
> 2) the user arrived from a link to a specific news to news.php?id=10
>
> It should display the news with id = 10 as the main news and get the
> latest ones to display in a list of other news
>
> I've so far was able to add a dinamic WHERE to my query ( if I have or
> not the id GET parameter ) and if I don't have it, I'm able to display
> the latest result as the main news, but when I have an id as a GET
> parameter, I have a where clause in my query and it will return only the
> main news and not build up the news list
>
> what I want is to separate the news that the user want to see ( the
> id=XX one ) from the others rows, can someone advice me ?
>
> Here is the code I have so far, I hope it serve as a better explanation
> than mine!
>
> <?
> $newsId = $_GET['id'];
> if (isset($newsID)){
> $whereClause = 'WHERE auto_id ='.$newsId;
> } else {
> $whereClause = '';
> }
> mysql_connect("localhost",$user,$pass) or die (mysql_error());
> mysql_select_db ($db_table);
> $SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC";
> $news_Query = mysql_query($SQL);
> $recordCount = mysql_numrows($news_Query);
> mysql_close();
> ?>
>
> TIA
> Marcelo Wolfgang
>

If id is set, query the DB for this news article and put as the first
element in an array. Then perform a second query WHERE ID != id and append
the results to the array. If id isn't set, just perform the one query
without any where clause.

If you want to do it all in one query, if id is provided use SELECT... WHERE
ID = id UNION (SELECT...WHERE ID != id ORDER BY id DESC) to get the ordering
you want. If id isn't set just use SELECT ... ORDER BY id DESC.

I'm not sure if there would be much difference in performance as I still
think the database would perform two queries internally.

Edward

attached mail follows:


> -----Original Message-----
> From: Alister Bulman [mailto:abulmangmail.com]
> Sent: 04 May 2007 15:07
> To: php-generallists.php.net
> Subject: Re: [PHP] Selecting a special row from the database
>
>
> On 04/05/07, Marcelo Wolfgang <marcelow3ol.com.br> wrote:
>
> > I'm building a news display page for a website, and since the user has 2
> > ways to arrive there, I want to know if this is possible:
> >
> > 1) the user arrive at news.php
> >
> > I will run a query at the db, and get the latest news to be the main one
> > (full display) and display the others news in a list
> >
> > 2) the user arrived from a link to a specific news to news.php?id=10
> >
> > It should display the news with id = 10 as the main news and get the
> > latest ones to display in a list of other news
>
> > Here is the code I have so far, I hope it serve as a better explanation
> > than mine!
>
> > <?
> > $newsId = $_GET['id'];
> > if (isset($newsID)){
> > $whereClause = 'WHERE auto_id ='.$newsId;
> > } else {
> > $whereClause = '';
> > }
> > mysql_connect("localhost",$user,$pass) or die (mysql_error());
> > mysql_select_db ($db_table);
> > $SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC";
>
> Yep, thats pretty classic.
> One thing I would do - assuming $newsId should always be an integer
>
> $whereClause = '';
> if (isset($_GET['id']) {
> $newsId = intval($_GET['id']);
> if ($newsId) // if not 0
> $whereClause = 'WHERE auto_id ='.$newsId;
> }
> .....
>
>
> Alister
>

This doesn't solve the problem. If ID is set, you'll only get one result.
Several results are always required, just with a different ordering. See my
other reply.

Edward

attached mail follows:


Edward Kay skrev:
>
>> -----Original Message-----
>> From: Marcelo Wolfgang [mailto:marcelow3ol.com.br]
>> Sent: 04 May 2007 14:37
>> To: php-generallists.php.net
>> Subject: [PHP] Selecting a special row from the database
>>
>>
>> Hi all,
>>
>> I'm building a news display page for a website, and since the user has 2
>> ways to arrive there, I want to know if this is possible:
>>
>> 1) the user arrive at news.php
>>
>> I will run a query at the db, and get the latest news to be the main one
>> (full display) and display the others news in a list
>>
>> 2) the user arrived from a link to a specific news to news.php?id=10
>>
>> It should display the news with id = 10 as the main news and get the
>> latest ones to display in a list of other news
>>
>> I've so far was able to add a dinamic WHERE to my query ( if I have or
>> not the id GET parameter ) and if I don't have it, I'm able to display
>> the latest result as the main news, but when I have an id as a GET
>> parameter, I have a where clause in my query and it will return only the
>> main news and not build up the news list
>>
>> what I want is to separate the news that the user want to see ( the
>> id=XX one ) from the others rows, can someone advice me ?
>>
>> Here is the code I have so far, I hope it serve as a better explanation
>> than mine!
>>
>> <?
>> $newsId = $_GET['id'];
>> if (isset($newsID)){
>> $whereClause = 'WHERE auto_id ='.$newsId;
>> } else {
>> $whereClause = '';
>> }
>> mysql_connect("localhost",$user,$pass) or die (mysql_error());
>> mysql_select_db ($db_table);
>> $SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC";
>> $news_Query = mysql_query($SQL);
>> $recordCount = mysql_numrows($news_Query);
>> mysql_close();
>> ?>
>>
>> TIA
>> Marcelo Wolfgang
>>
>
> If id is set, query the DB for this news article and put as the first
> element in an array. Then perform a second query WHERE ID != id and append
> the results to the array. If id isn't set, just perform the one query
> without any where clause.
>
> If you want to do it all in one query, if id is provided use SELECT... WHERE
> ID = id UNION (SELECT...WHERE ID != id ORDER BY id DESC) to get the ordering
> you want. If id isn't set just use SELECT ... ORDER BY id DESC.
>
> I'm not sure if there would be much difference in performance as I still
> think the database would perform two queries internally.
>
> Edward
>

Maybe
SELECT ..., if (id = my_id,1,0) as foo
...
ORDER BY foo DESC;

attached mail follows:


> -----Original Message-----
> From: Fredrik Thunberg [mailto:thuniswebguidepartner.com]
> Sent: 04 May 2007 15:31
> To: Edward Kay
> Cc: php-generallists.php.net
> Subject: Re: [PHP] Selecting a special row from the database
>
> Edward Kay skrev:
> >
> >> -----Original Message-----
> >> From: Marcelo Wolfgang [mailto:marcelow3ol.com.br]
> >> Sent: 04 May 2007 14:37
> >> To: php-generallists.php.net
> >> Subject: [PHP] Selecting a special row from the database
> >>
> >>
> >> Hi all,
> >>
> >> I'm building a news display page for a website, and since the
> user has 2
> >> ways to arrive there, I want to know if this is possible:
> >>
> >> 1) the user arrive at news.php
> >>
> >> I will run a query at the db, and get the latest news to be
> the main one
> >> (full display) and display the others news in a list
> >>
> >> 2) the user arrived from a link to a specific news to news.php?id=10
> >>
> >> It should display the news with id = 10 as the main news and get the
> >> latest ones to display in a list of other news
> >>
> >> I've so far was able to add a dinamic WHERE to my query ( if I have or
> >> not the id GET parameter ) and if I don't have it, I'm able to display
> >> the latest result as the main news, but when I have an id as a GET
> >> parameter, I have a where clause in my query and it will
> return only the
> >> main news and not build up the news list
> >>
> >> what I want is to separate the news that the user want to see ( the
> >> id=XX one ) from the others rows, can someone advice me ?
> >>
> >> Here is the code I have so far, I hope it serve as a better explanation
> >> than mine!
> >>
> >> <?
> >> $newsId = $_GET['id'];
> >> if (isset($newsID)){
> >> $whereClause = 'WHERE auto_id ='.$newsId;
> >> } else {
> >> $whereClause = '';
> >> }
> >> mysql_connect("localhost",$user,$pass) or die (mysql_error());
> >> mysql_select_db ($db_table);
> >> $SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC";
> >> $news_Query = mysql_query($SQL);
> >> $recordCount = mysql_numrows($news_Query);
> >> mysql_close();
> >> ?>
> >>
> >> TIA
> >> Marcelo Wolfgang
> >>
> >
> > If id is set, query the DB for this news article and put as the first
> > element in an array. Then perform a second query WHERE ID != id
> and append
> > the results to the array. If id isn't set, just perform the one query
> > without any where clause.
> >
> > If you want to do it all in one query, if id is provided use
> SELECT... WHERE
> > ID = id UNION (SELECT...WHERE ID != id ORDER BY id DESC) to get
> the ordering
> > you want. If id isn't set just use SELECT ... ORDER BY id DESC.
> >
> > I'm not sure if there would be much difference in performance as I still
> > think the database would perform two queries internally.
> >
> > Edward
> >
>
> Maybe
> SELECT ..., if (id = my_id,1,0) as foo
> ...
> ORDER BY foo DESC;
>

Good idea! Just tried it out and it works really well.

attached mail follows:


Edward Kay a écrit :
>
>> -----Original Message-----
>> From: Fredrik Thunberg [mailto:thuniswebguidepartner.com]
>> Sent: 04 May 2007 15:31
>> To: Edward Kay
>> Cc: php-generallists.php.net
>> Subject: Re: [PHP] Selecting a special row from the database
>>
>> Edward Kay skrev:
>>>> -----Original Message-----
>>>> From: Marcelo Wolfgang [mailto:marcelow3ol.com.br]
>>>> Sent: 04 May 2007 14:37
>>>> To: php-generallists.php.net
>>>> Subject: [PHP] Selecting a special row from the database
>>>>
>>>>
>>>> Hi all,
>>>>
>>>> I'm building a news display page for a website, and since the
>> user has 2
>>>> ways to arrive there, I want to know if this is possible:
>>>>
>>>> 1) the user arrive at news.php
>>>>
>>>> I will run a query at the db, and get the latest news to be
>> the main one
>>>> (full display) and display the others news in a list
>>>>
>>>> 2) the user arrived from a link to a specific news to news.php?id=10
>>>>
>>>> It should display the news with id = 10 as the main news and get the
>>>> latest ones to display in a list of other news
>>>>
>>>> I've so far was able to add a dinamic WHERE to my query ( if I have or
>>>> not the id GET parameter ) and if I don't have it, I'm able to display
>>>> the latest result as the main news, but when I have an id as a GET
>>>> parameter, I have a where clause in my query and it will
>> return only the
>>>> main news and not build up the news list
>>>>
>>>> what I want is to separate the news that the user want to see ( the
>>>> id=XX one ) from the others rows, can someone advice me ?
>>>>
>>>> Here is the code I have so far, I hope it serve as a better explanation
>>>> than mine!
>>>>
>>>> <?
>>>> $newsId = $_GET['id'];
>>>> if (isset($newsID)){
>>>> $whereClause = 'WHERE auto_id ='.$newsId;
>>>> } else {
>>>> $whereClause = '';
>>>> }
>>>> mysql_connect("localhost",$user,$pass) or die (mysql_error());
>>>> mysql_select_db ($db_table);
>>>> $SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC";
>>>> $news_Query = mysql_query($SQL);
>>>> $recordCount = mysql_numrows($news_Query);
>>>> mysql_close();
>>>> ?>
>>>>
>>>> TIA
>>>> Marcelo Wolfgang
>>>>
>>> If id is set, query the DB for this news article and put as the first
>>> element in an array. Then perform a second query WHERE ID != id
>> and append
>>> the results to the array. If id isn't set, just perform the one query
>>> without any where clause.
>>>
>>> If you want to do it all in one query, if id is provided use
>> SELECT... WHERE
>>> ID = id UNION (SELECT...WHERE ID != id ORDER BY id DESC) to get
>> the ordering
>>> you want. If id isn't set just use SELECT ... ORDER BY id DESC.
>>>
>>> I'm not sure if there would be much difference in performance as I still
>>> think the database would perform two queries internally.
>>>
>>> Edward
>>>
>> Maybe
>> SELECT ..., if (id = my_id,1,0) as foo
>> ...
>> ORDER BY foo DESC;
>>
>
> Good idea! Just tried it out and it works really well.

Hello,

If you're looking for performance, why do you select everything for
articles that are not in full display ?
Isn't it better if you SELECT * just for the article you want in full
display and make another query for other titles ?
LIMIT would also help performance.
Cheers

--
Emmanuel

attached mail follows:


On Fri, May 4, 2007 8:36 am, Marcelo Wolfgang wrote:
> I'm building a news display page for a website, and since the user has
> 2
> ways to arrive there, I want to know if this is possible:
>
> 1) the user arrive at news.php
>
> I will run a query at the db, and get the latest news to be the main
> one
> (full display) and display the others news in a list
>
> 2) the user arrived from a link to a specific news to news.php?id=10
>
> It should display the news with id = 10 as the main news and get the
> latest ones to display in a list of other news
>
> I've so far was able to add a dinamic WHERE to my query ( if I have or
> not the id GET parameter ) and if I don't have it, I'm able to display
> the latest result as the main news, but when I have an id as a GET
> parameter, I have a where clause in my query and it will return only
> the
> main news and not build up the news list
>
> what I want is to separate the news that the user want to see ( the
> id=XX one ) from the others rows, can someone advice me ?

> Here is the code I have so far, I hope it serve as a better
> explanation
> than mine!
>
> <?
> $newsId = $_GET['id'];
> if (isset($newsID)){
> $whereClause = 'WHERE auto_id ='.$newsId;

SQL injection attack alert:
You *really* need to sanitize this input.
http://phpsec.org/

> } else {
> $whereClause = '';
> }
> mysql_connect("localhost",$user,$pass) or die (mysql_error());
> mysql_select_db ($db_table);
> $SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC";

Using select * is usually a bad idea anyway, but you can also add:
$newsId = (int) $newsId;
select *, auto_id = $newsId as requested from ...

This then gives PHP a way to tell if this is a story they ASKED FOR by
id, or just a story, as you have an "extra" filed called 'requested'

This assumes that you never ever have 0 as an ID in the database, as
the (int) typecast will force it to 0 if you don't have a $newsId, but
you almost for sure won't have a 0 for auto_id, as it's an
auto_increment field that starts at 1 and goes up to over 2 billion.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

attached mail follows:


On Fri, May 4, 2007 9:26 am, Edward Kay wrote:
>> what I want is to separate the news that the user want to see ( the
>> id=XX one ) from the others rows, can someone advice me ?
>>
>> Here is the code I have so far, I hope it serve as a better
>> explanation
>> than mine!
>>
>> <?
>> $newsId = $_GET['id'];

/*
>> if (isset($newsID)){
>> $whereClause = 'WHERE auto_id ='.$newsId;
>> } else {
>> $whereClause = '';
>> }
*/

>> mysql_connect("localhost",$user,$pass) or die (mysql_error());
>> mysql_select_db ($db_table);
>> $SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id
>> DESC";

Also, forget the where clause and change your ORDER BY to be:

ORDER BY auto_id = $newsId desc, auto_id desc

This will FIRST check the ID to see if it's the one you want from the
one story, then the rest in id descending format.

And you probably should not use "auto_id desc" but "postdate desc" or
whatever date field you are using to date the stories...

Technically speaking, you should NOT rely on the fact that mysql will
be adding 1 to each id to get the next one.

That happens to be how it works, and it's really unlikely to change,
but if you ever get to where you have a humongous site and a zillion
news stories in federated databases, you suddenly have this buglet
where your ID is *not* the thing you wanted to sort by.

And, in theory, the MySQL guys could change the implementation of
auto_increment out from under you, tho that's even less likely than
needing a federated db setup... :-)

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

attached mail follows:


Hello.

I am currently working on a script that parses a given http adress by
looking for anchor tags, background images and so on - a crawler if
you like. The downloaded content is temporarily stored on the server
(Mac OS X Server 10.4.9 with PHP 5) and, when the script is done, the
content is packed into a ZIP archive. It seems that I am having
trouble with my Apache timeout setting. Because the script downloads
between 250 and 300MB of html, pdf, css files and so on, it is
terminated automatically after the specified timeout setting
(currently 1200 seconds). Setting max execution time to -1 in the
script has no effect (which has been noticed previously on the
php.net manual page).

Is there any other way (with PHP) to come around this problem besides
setting the time-out in the Apache config to more than 1200 seconds?
The Apache manual says that the time out value can only be changed
within the core configuration scope. My initial idea was to set the
value in a .htaccess file which unfortunately is not allowed. I might
also add that the script is already optimized for speed so to say.

Hope you get what I mean.

//frank

attached mail follows:


Frank Arensmeier a écrit :
> Hello.
>
> I am currently working on a script that parses a given http adress by
> looking for anchor tags, background images and so on - a crawler if you
> like. The downloaded content is temporarily stored on the server (Mac OS
> X Server 10.4.9 with PHP 5) and, when the script is done, the content is
> packed into a ZIP archive. It seems that I am having trouble with my
> Apache timeout setting. Because the script downloads between 250 and
> 300MB of html, pdf, css files and so on, it is terminated automatically
> after the specified timeout setting (currently 1200 seconds). Setting
> max execution time to -1 in the script has no effect (which has been
> noticed previously on the php.net manual page).
>
> Is there any other way (with PHP) to come around this problem besides
> setting the time-out in the Apache config to more than 1200 seconds? The
> Apache manual says that the time out value can only be changed within
> the core configuration scope. My initial idea was to set the value in a
> .htaccess file which unfortunately is not allowed. I might also add that
> the script is already optimized for speed so to say.
>
> Hope you get what I mean.
>
> //frank

Hello Frank

Are you really sure you need an Apache-spawned PHP script to do all that
long stuff ? Even if Apache does not give up on your PHP script, the
HTTP client might do so. This is also not a good idea for a site with
several clients because Apache could easily run low on available
sockets, causing a DoS.

I suggest you just spawn a background process from your PHP script,
through some shell command like batch and nohup. The background process
can still be coded in PHP with the CLI interface.
At the end of the long process, you alert the user job was done (e.g.
by mail or by some kind of AJAX mechanism) and let him download the
result.

In the Apache-spawned script:

<?php
// This will launch the process in background.
// Be sure to set $job_id.
$cmd_path = "/path/to/some/job/dir/job$job_id.sh";
$cmd = fopen( $cmd_path, 'w' );
fwrite(
   $cmd,
   "#!/bin/sh\n".
   "nohup php -f /path/to/your/scripts/long_process.php someargs\n".
   "rm -f $cmd_path" );
fclose( $cmd );
shell_exec( "batch -f $cmd_path" );

// Tell the user the job was scheduled...
?>

In long_process.php:

<?php
// Do your stuff...

// Send an e-mail to the user or change a persistent server-side
// state so that a script called periodically by the client will let
// her know it was done.
?>

You may need to give the right to www-data, or whatever account running
Apache, to create jobs through at/batch.

Regards

--
Emmanuel

attached mail follows:


// sorry for posting my answer off list... //

4 maj 2007 kl. 17.35 skrev Emmanuel Raulo-Kumagai:

> Frank Arensmeier a écrit :
>> Hello.
>> I am currently working on a script that parses a given http adress
>> by looking for anchor tags, background images and so on - a
>> crawler if you like. The downloaded content is temporarily stored
>> on the server (Mac OS X Server 10.4.9 with PHP 5) and, when the
>> script is done, the content is packed into a ZIP archive. It seems
>> that I am having trouble with my Apache timeout setting. Because
>> the script downloads between 250 and 300MB of html, pdf, css files
>> and so on, it is terminated automatically after the specified
>> timeout setting (currently 1200 seconds). Setting max execution
>> time to -1 in the script has no effect (which has been noticed
>> previously on the php.net manual page).
>> Is there any other way (with PHP) to come around this problem
>> besides setting the time-out in the Apache config to more than
>> 1200 seconds? The Apache manual says that the time out value can
>> only be changed within the core configuration scope. My initial
>> idea was to set the value in a .htaccess file which unfortunately
>> is not allowed. I might also add that the script is already
>> optimized for speed so to say.
>> Hope you get what I mean.
>> //frank
>
> Hello Frank
>
> Are you really sure you need an Apache-spawned PHP script to do all
> that
> long stuff ? Even if Apache does not give up on your PHP script, the
> HTTP client might do so. This is also not a good idea for a site with
> several clients because Apache could easily run low on available
> sockets, causing a DoS.
>
> I suggest you just spawn a background process from your PHP script,
> through some shell command like batch and nohup. The background
> process
> can still be coded in PHP with the CLI interface.

Thank you for sharing your suggestions.

The idea of running the script as a background process seems very
elegant to me, I have to admit. Since my script is executed only once
a week, it would be sufficient to set up a simple cron job.
Modifications to the script are also rather small, since I already
have e.g. functions for output logging, process locking and so on.

> At the end of the long process, you alert the user job was done (e.g.
> by mail or by some kind of AJAX mechanism) and let him download the
> result.
>
> In the Apache-spawned script:
>
> <?php
> // This will launch the process in background.
> // Be sure to set $job_id.
> $cmd_path = "/path/to/some/job/dir/job$job_id.sh";
> $cmd = fopen( $cmd_path, 'w' );
> fwrite(
> $cmd,
> "#!/bin/sh\n".
> "nohup php -f /path/to/your/scripts/long_process.php someargs\n".
> "rm -f $cmd_path" );
> fclose( $cmd );
> shell_exec( "batch -f $cmd_path" );
>
> // Tell the user the job was scheduled...
> ?>
>
> In long_process.php:
>
> <?php
> // Do your stuff...
>
> // Send an e-mail to the user or change a persistent server-side
> // state so that a script called periodically by the client will let
> // her know it was done.
> ?>
>
> You may need to give the right to www-data, or whatever account
> running
> Apache, to create jobs through at/batch.
>
> Regards
>
> --
> Emmanuel
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

attached mail follows:


On Fri, May 4, 2007 8:37 am, Frank Arensmeier wrote:
> I am currently working on a script that parses a given http adress by
> looking for anchor tags, background images and so on - a crawler if
> you like. The downloaded content is temporarily stored on the server
> (Mac OS X Server 10.4.9 with PHP 5) and, when the script is done, the
> content is packed into a ZIP archive. It seems that I am having
> trouble with my Apache timeout setting. Because the script downloads
> between 250 and 300MB of html, pdf, css files and so on, it is
> terminated automatically after the specified timeout setting
> (currently 1200 seconds). Setting max execution time to -1 in the
> script has no effect (which has been noticed previously on the
> php.net manual page).

You mean 0, not -1, right?...

Cuz 0 means "forever" and -1 probably doesn't mean anything at all,
unless it means 0xffffffff seconds, which is on heck of a long time.

You can often use set_time_limit inside your loop with a reasonable
number this is much longer than any single loop execution should take.

This provides you with as much time as you need to finish, without
wiping out ALL the benefits of the original intent of set_time_limit

> Is there any other way (with PHP) to come around this problem besides
> setting the time-out in the Apache config to more than 1200 seconds?

Wait a minute.

Are you talking about a PHP time limit, or an Apache time limit?!

Cuz we can't really help you much with some Apache time limit thingie...

> The Apache manual says that the time out value can only be changed
> within the core configuration scope. My initial idea was to set the
> value in a .htaccess file which unfortunately is not allowed. I might
> also add that the script is already optimized for speed so to say.

Not allowed as in you can't have .htaccess, or not allowed as in
somebody turned off the ability to change PHP's timeout setting?

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

attached mail follows:


4 maj 2007 kl. 21.58 skrev Richard Lynch:

> On Fri, May 4, 2007 8:37 am, Frank Arensmeier wrote:
>> I am currently working on a script that parses a given http adress by
>> looking for anchor tags, background images and so on - a crawler if
>> you like. The downloaded content is temporarily stored on the server
>> (Mac OS X Server 10.4.9 with PHP 5) and, when the script is done, the
>> content is packed into a ZIP archive. It seems that I am having
>> trouble with my Apache timeout setting. Because the script downloads
>> between 250 and 300MB of html, pdf, css files and so on, it is
>> terminated automatically after the specified timeout setting
>> (currently 1200 seconds). Setting max execution time to -1 in the
>> script has no effect (which has been noticed previously on the
>> php.net manual page).
>
> You mean 0, not -1, right?...

Well, yes. I think I mixed up the function "set_time_limit" with the
"memory_limit" option.

> Cuz 0 means "forever" and -1 probably doesn't mean anything at all,
> unless it means 0xffffffff seconds, which is on heck of a long time.
>
> You can often use set_time_limit inside your loop with a reasonable
> number this is much longer than any single loop execution should take.
>
> This provides you with as much time as you need to finish, without
> wiping out ALL the benefits of the original intent of set_time_limit
>
>> Is there any other way (with PHP) to come around this problem besides
>> setting the time-out in the Apache config to more than 1200 seconds?
>
> Wait a minute.
>
> Are you talking about a PHP time limit, or an Apache time limit?!

I was talking about the Apache time limit. As you most certainly
know, the Apache time limit is "superior" to the maximal execution
time set inside a PHP script. Therefore, setting the max execution
time to 0 (no limit) has no effect if the script reaches the Apache
time limit specified by the "TimeOut" directive.

Of course, since this is my own server and I have root access, I
could set the Apache time limit to a higher value. But, as Emmanuel
already pointed out ... "because Apache could easily run low on
available sockets, causing a DoS." So I do not feel that this is the
right way to go.

> Cuz we can't really help you much with some Apache time limit
> thingie...

I was afraid of that.

>
>> The Apache manual says that the time out value can only be changed
>> within the core configuration scope. My initial idea was to set the
>> value in a .htaccess file which unfortunately is not allowed. I might
>> also add that the script is already optimized for speed so to say.
>
> Not allowed as in you can't have .htaccess, or not allowed as in
> somebody turned off the ability to change PHP's timeout setting?

With "not allowed" I ment that you are not able to set the Apache
directive "timeout" in a .htaccess file (at least not with Apache
1.3) since this directive is only legal within the server core
configuration.

I still think that the best way to go is to not involve Apache at all
when running the script. Because the script already has functions for
output logging etc. it is no big deal to change the code so that it
can be run from PHP CLI.

//frank

> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?

attached mail follows:


I have enough fonts installed on my machine to draw most of the
world's UTF-8 characters. But they aren't all in one font file. How
can I use the resources I have to reliably draw any character using
imagetttext()?

For example: Most of the text I want to draw is regular ASCII, many
words contain Extended ASCII. Then some of it is Korean, Chinese,
Japanese or Arabic. I don't know when I'll come across what charset.
I want to draw them all. Is this even possible?
~Seth

attached mail follows:


On Fri, May 4, 2007 9:23 am, Seth Price wrote:
> I have enough fonts installed on my machine to draw most of the
> world's UTF-8 characters. But they aren't all in one font file. How
> can I use the resources I have to reliably draw any character using
> imagetttext()?
>
> For example: Most of the text I want to draw is regular ASCII, many
> words contain Extended ASCII. Then some of it is Korean, Chinese,
> Japanese or Arabic. I don't know when I'll come across what charset.
> I want to draw them all. Is this even possible?

I don't think there is any one giant charset you could have that would
slap all the languages together...

The whole point of a charset is to set up correspondences between
numbers and the "letter" you see.

So every different charset is just a mapping from a number to a
"glpyh" (the physical representation of the letter, like a series of
pen-strokes, as I understand it)

And presumably the guys making up UTF-8, UTF-16, and UTF-32 didn't
make these numbers up just for fun, and actually have languages that
NEED 32 bits to represent every "letter".

I suppose, in theory, you could take every charset, and create a
UTF-40 which used 40 bits, and use the first byte (8 bits) for an
"offset" and then you could map your super-charset back to normal
charsets, assuming there are no more than 255 languages to support.

I guess if there's more than 255 languages, you're looking at even
more bits/bytes...

Sounds like a lot of work, though...

Maybe ask over on the i18n PHP mailing list, as they're way more
familiar with this stuff than most users here.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

attached mail follows:


Ah, thanks, I didn't notice a i18n mailing list. I'll try there.

Maybe if I had a list of font files, I could test each to work with a
given string, until I find one which works?
~Seth

On May 4, 2007, at 2:54 PM, Richard Lynch wrote:

>
>
> On Fri, May 4, 2007 9:23 am, Seth Price wrote:
>> I have enough fonts installed on my machine to draw most of the
>> world's UTF-8 characters. But they aren't all in one font file. How
>> can I use the resources I have to reliably draw any character using
>> imagetttext()?
>>
>> For example: Most of the text I want to draw is regular ASCII, many
>> words contain Extended ASCII. Then some of it is Korean, Chinese,
>> Japanese or Arabic. I don't know when I'll come across what charset.
>> I want to draw them all. Is this even possible?
>
> I don't think there is any one giant charset you could have that would
> slap all the languages together...
>
> The whole point of a charset is to set up correspondences between
> numbers and the "letter" you see.
>
> So every different charset is just a mapping from a number to a
> "glpyh" (the physical representation of the letter, like a series of
> pen-strokes, as I understand it)
>
> And presumably the guys making up UTF-8, UTF-16, and UTF-32 didn't
> make these numbers up just for fun, and actually have languages that
> NEED 32 bits to represent every "letter".
>
> I suppose, in theory, you could take every charset, and create a
> UTF-40 which used 40 bits, and use the first byte (8 bits) for an
> "offset" and then you could map your super-charset back to normal
> charsets, assuming there are no more than 255 languages to support.
>
> I guess if there's more than 255 languages, you're looking at even
> more bits/bytes...
>
> Sounds like a lot of work, though...
>
> Maybe ask over on the i18n PHP mailing list, as they're way more
> familiar with this stuff than most users here.
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
>
>

attached mail follows:


On Saturday 05 May 2007 04:24, Seth Price wrote:

> Maybe if I had a list of font files, I could test each to work with a
> given string, until I find one which works?

You could try looking for a comprehensive iso-10646 font.

--
Crayon

attached mail follows:


Hello,

I'm trying to send a ZIP file generated on the fly in a temporary directory.
The ZIP file is created successfully and I'm using the following code to send it to the client :

    $filesize=filesize($path);
    $mimetype='application/zip';

    // Make sure there's not anything else left
    ob_clean_all();

    // Start sending headers
    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers
    header("Content-Transfer-Encoding: binary");
    header("Content-Description: File Transfer");
    header("Content-Type: ".$mimetype);
    header("Content-Disposition: attachment; filename=\"".$name."\";" );
    header("Content-Length: ".$filesize);

    $fp=fopen($path,"rb");
    while(!feof($fp))
    {
        set_time_limit(0);
        print fread($fp, 8192);
    }
    fclose($fp);

The ob_clean_all() function :
function ob_clean_all () {
    $ob_active = ob_get_length () !== false;
    while($ob_active) {
        ob_end_clean();
        $ob_active = ob_get_length () !== false;
    }

    return true;
}

The problem is that Apache process the output throught gzip and so drop the Content-Length header replacing it with a chunked transfer. This should work fine but Internet Explorer simply save the raw gzip compressed data instead of the ZIP archive. However this works fine with Firefox.

gzip encoding is unecessary since I'm transfering a ZIP archive, so I think just disabling it should solve the problem, but I haven't found how to do this.

Any help would be appreciated.

--
strawks.

             
---------------------------------
 Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.

attached mail follows:


strawks a écrit :
> Hello,
>
> I'm trying to send a ZIP file generated on the fly in a temporary directory.
> The ZIP file is created successfully and I'm using the following code to send it to the client :
>
> $filesize=filesize($path);
> $mimetype='application/zip';
>
> // Make sure there's not anything else left
> ob_clean_all();
>
> // Start sending headers
> header("Pragma: public"); // required
> header("Expires: 0");
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Cache-Control: private",false); // required for certain browsers
> header("Content-Transfer-Encoding: binary");
> header("Content-Description: File Transfer");
> header("Content-Type: ".$mimetype);
> header("Content-Disposition: attachment; filename=\"".$name."\";" );
> header("Content-Length: ".$filesize);
>
> $fp=fopen($path,"rb");
> while(!feof($fp))
> {
> set_time_limit(0);
> print fread($fp, 8192);
> }
> fclose($fp);
>
> The ob_clean_all() function :
> function ob_clean_all () {
> $ob_active = ob_get_length () !== false;
> while($ob_active) {
> ob_end_clean();
> $ob_active = ob_get_length () !== false;
> }
>
> return true;
> }
>
> The problem is that Apache process the output throught gzip and so drop the Content-Length header replacing it with a chunked transfer. This should work fine but Internet Explorer simply save the raw gzip compressed data instead of the ZIP archive. However this works fine with Firefox.
>
> gzip encoding is unecessary since I'm transfering a ZIP archive, so I think just disabling it should solve the problem, but I haven't found how to do this.
>
> Any help would be appreciated.
>

Hello,

I have about the same code except that I use "application/x-zip-archive"
for the content type and it just works.
There's no ob_* stuff in my code also.

'hope that helps you out...

--
Emmanuel

attached mail follows:


On Fri, May 4, 2007 9:56 am, strawks wrote:
> $filesize=filesize($path);
> $mimetype='application/zip';
>
> // Make sure there's not anything else left
> ob_clean_all();
>
> // Start sending headers
> header("Pragma: public"); // required
> header("Expires: 0");
> header("Cache-Control: must-revalidate, post-check=0,
> pre-check=0"