php-general Digest 6 Mar 2006 08:20:37 -0000 Issue 4000

Topics (messages 231475 through 231494):

Re: output Today's date
        231475 by: jblanchard.pocket.com
        231484 by: Curt Zirzow

Re: Mysql Rows
        231476 by: jblanchard.pocket.com
        231480 by: Curt Zirzow
        231492 by: Gustav Wiberg
        231493 by: tedd

Re: DOMElement::setAttribute() manual example question
        231477 by: Andreas Korthaus
        231478 by: Rob

Re: Prepared statements
        231479 by: Julius Hacker
        231485 by: Curt Zirzow
        231487 by: Anthony Ettinger

Re: [JOB] LAMP Developers, Los Angeles | 70-120k
        231481 by: Rory Browne
        231483 by: Curt Zirzow

Re: php/mysql/phpMyAdmin on an iBook?
        231482 by: Larry E. Ullman

simplify DOM api
        231486 by: Andreas Korthaus

How can I tell if an output stream is finished?
        231488 by: Al
        231490 by: Satyam
        231491 by: Al
        231494 by: Barry

create xml root-element with xmlns and xsd link (using DOM)
        231489 by: Andreas Korthaus

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
[snip]
ls there anyway I can set the date to the timezone of the clients
timezone?  For example, if a person opens the web page at 3/6 12:01
EST and another person opens the same page at 3/5 10:01 MST I would
like the date to be the above days on the client computers.  I know
everyone knows this but the way I described this the two people
accessed the webpage at the same time but I want the correct date for
the client computer to be outputted.
[/snip]

A client side problem requires a client side solution, you will need
JavaScript to do this.

--- End Message ---
--- Begin Message ---
On Sat, Mar 04, 2006 at 07:01:55PM -0700, Paul Goepfert wrote:
> Hi all,
> 
> ls there anyway I can set the date to the timezone of the clients
> timezone?  For example, if a person opens the web page at 3/6 12:01
> EST and another person opens the same page at 3/5 10:01 MST I would
> like the date to be the above days on the client computers.  I know
> everyone knows this but the way I described this the two people
> accessed the webpage at the same time but I want the correct date for
> the client computer to be outputted.

There are some tools that you can detect where the person is
located and and you would be able to use the timezone from that
information. One site I found from a quick google search:

 http://www.ip2location.com/


The cheapest and simpliest method would be to use some javascript
to detect the timezone. Or let the user specify which one he wants
to use.


Curt.
-- 
cat .signature: No such file or directory

--- End Message ---
--- Begin Message ---
[snip]
R O B said:

>That Rod guy, he's such a card! I'd add something, but Jay has already
>covered my list in a more recent email than this one to which I'm
>responding :)

jblanchard (who I think is Rod) said:
[/snip]

I am definitely not Rod.

[snip]
For sake of argument, let's agree that renumbering dB's is not a good 
idea -- so if you want to sequentially step through the records, then 
how do you do it?
[/snip]

You must have a column that is sequential in some way. An
auto-incremented column, timestamp, or some other device that will allow
you to step through regardless of gaps in sequence. If you do not have
such a column then you could add one.

--- End Message ---
--- Begin Message ---
On Sun, Mar 05, 2006 at 08:01:07AM -0500, tedd wrote:
> R O B said:
> 
> >That Rod guy, he's such a card! I'd add something, but Jay has already
> >covered my list in a more recent email than this one to which I'm
> >responding :)
> 
> jblanchard (who I think is Rod) said:
> 
> >A SQL question on a PHP mailing list usually gets more than ribbing. ;)
 
So, Jay is Rod, who is this Rob person?  Now I'm really confused.


Curt.
-- 
cat .signature: No such file or directory

--- End Message ---
--- Begin Message --- ----- Original Message ----- From: "tedd" <[EMAIL PROTECTED]>
To: <[email protected]>
Cc: "Gustav Wiberg" <[EMAIL PROTECTED]>; "Robert Cummings" <[EMAIL PROTECTED]>
Sent: Sunday, March 05, 2006 12:58 AM
Subject: Re: [PHP] Mysql Rows


Hi:

Gustav said:

No, maybe not when it's a small db, but when you try to delete 50.000 posts I have a strong feeling this would be very much slower then if you don't alter table after each deletion.

First, I'm not deleting 50,000 records -- I dropping a table and renumbering it.

In any event, I just tested your claim on my host and I was able to renumber 50,000 records in less than 1/2 second. Even though I tried it several times, the results were never above 0.47 seconds. If I was dealing with a database that was accessible to others, then I would either lock tables or use transaction and then renumber -- but in either case the difference in time is less than additional 1/10 of a second.
Ok, it wasn't really a claim, it was more a "feeling", but I couldn't say it for sure, so I applogize for misleading you there! :-)

Half a second or 0.47 seconds may not be a big issue, but as I see it this could be "unessescary time", if you could achieve the same functionality (without doing some alter-statements) faster and without have to lock the db. Have you tested without the alter-table statement? *just curious*

Aha... I missed the part ...
"I was dealing with a database that was accessible to others"
Only YOU are using the db? Ok, then it would not be a problem.






I don't know if 1/2 second is a big deal in your world, or not, but it seems a bit slow to me. I wrote splay binary tree search routine that would perform 100,000 searches in a two million record dB in less than one second on my Mac. And if you know what a splay algorithm is, then you also know that it not only preforms a search but then reorders the tree each time a search is successful and thus is very laborious. Yet the time it took to preform 100,000 searches and reorders was still less than one second.

Perhaps my host is running something slower -- after all, I'm only paying $7.00 per year for the service. But with all things considered, a half second is not that significant with a small 50,000 record dB. That's probably less than the majority of web sites that use MySQL, don't you think?

Ok, I got your point! :-) But there is another side to it , and that is scalability. Ok, you don't have so many posts in your database.
Ok, it does take less then a second...

What if you had do make the db visible to other users? Then this link that might intrest you: (it's about pitfalls with transactions as may see in the link)
http://www.onlamp.com/pub/a/php/2003/12/18/transaction_pitfalls.htmlhttp://www.onlamp.com/pub/a/php/2003/12/18/transaction_pitfalls.html

But what If you suddenly hade to change host for some reason... The new host server maybe wouldn't be as fast as yours is today. And as someone mentioned, what about if your db was growing to include a couple of million posts.

Of course, if you don't think your db will grow so much, and it works fine, then of course you could contiuning doing the ALTER-statement thing, but there's always two sides of the story... ;-)

"That's probably less than the majority of web sites that use MySQL, don't you think?"
I really have no clue, I could only guess... :-)


Rod said:

*LOL* I knew those MySQL people shouldn't have made the ALTER TABLE
syntax available to just anyone. Gun --> foot --> *BLAM*. I hope to God
you never get your hands on a real database with millions of entries.

I'm glad that you were amused. Considering that I was talking about a flat dB, then you have already shot yourself in the foot if your "real database" is in the millions of entries and is flat. I hope to God that normalization may be something you consider in your next database design.

In any event, it's interesting that I posted a question here and I expected some ribbing, but I also expected something of value.

If the ALTER TABLE statement is prone to error, then I would like to know that and why. However, I suspect that claim isn't true, it's just that it's misuse has generated an urban myth of "Don't do that! That's dangerous!" without any real substance other than for programer error.
*LOL* I have to say, that I agree with you on this one. I've searched on issues/regarding ALTER TABLE, and could only find errors regarding this when
Microsoft was involved ;-)

Of course, I've run into windozes programmers who
accept the occasional crash and burn as "it comes with the territory", but that's unfortunate to apply this "apprehension" to MySQL.
:-)


In my previous post I pleaded for someone to point out the error of my ways and to give me an alternative, but that hasn't happened yet -- so, does anyone want to tell me why I should not renumber a flat database and give me an alternative? I'm all ears...

I have thought of this...
...but isn't there a function in MySQL or PHP to retrieve the absolute recordnr of a db???


...if there is not, then your code IS good, if you absolutelty need the functionality! :-)

/G

--- End Message ---
--- Begin Message ---
Gustav:

In any event, I just tested your claim on my host and I was able to renumber 50,000 records in less than 1/2 second. Even though I tried it several times, the results were never above 0.47 seconds. If I was dealing with a database that was accessible to others, then I would either lock tables or use transaction and then renumber -- but in either case the difference in time is less than additional 1/10 of a second.
Ok, it wasn't really a claim, it was more a "feeling", but I couldn't say it for sure, so I applogize for misleading you there! :-)

No need to apologize, this is an open discussion -- I'm the one who is asking questions.

Aha... I missed the part ...
"I was dealing with a database that was accessible to others"
Only YOU are using the db? Ok, then it would not be a problem.

Well both. If I was the only one working with the dB, then there is no need to lock it down. However, I did set up test where I did lock it down and another test where I set up a transaction and both added about a tenth of a second to the alteration of 50,000 records.

Ok, I got your point! :-) But there is another side to it , and that is scalability. Ok, you don't have so many posts in your database.
Ok, it does take less then a second...

What if you had do make the db visible to other users?

As I said I did a LOCK TABLE, that's where no one can access the records while I work on them (at least that's my understanding) and it added about a tenth of a second to the overall time (just over 1/2 second for 50,000 records). I also preformed a transaction (BEGIN/COMMIT), which my understanding is that it checks to make sure that the operation can be preformed and then if everything can be done, then it does it -- an interesting feature.

Then this link that might intrest you: (it's about pitfalls with transactions as may see in the link)
http://www.onlamp.com/pub/a/php/2003/12/18/transaction_pitfalls.htmlhttp://www.onlamp.com/pub/a/php/2003/12/18/transaction_pitfalls.html

I'll read the link, thanks.

But what If you suddenly hade to change host for some reason... The new host server maybe wouldn't be as fast as yours is today. And as someone mentioned, what about if your db was growing to include a couple of million posts.

Both valid points -- but I know the limits of my customer. If they post more than 100,000 records in their lifetime, I would be very surprised.

Of course, if you don't think your db will grow so much, and it works fine, then of course you could contiuning doing the ALTER-statement thing, but there's always two sides of the story... ;-)

Well... what I am developing is something for a civilian (i.e., no programming experience at all). They want to be able to add, edit, and delete records at their command. I know that I could not explain why when they deleted a record that they would no longer have the index again, for I couldn't think of any reason myself -- other than "it's bad form". So, I needed a way for them to delete a record and make it easy for them to understand. However, I also wanted to make sure that I wasn't doing them a disservice -- and thus my questions to this group -- the other side of the story.

If the ALTER TABLE statement is prone to error, then I would like to know that and why. However, I suspect that claim isn't true, it's just that it's misuse has generated an urban myth of "Don't do that! That's dangerous!" without any real substance other than for programer error.
*LOL* I have to say, that I agree with you on this one. I've searched on issues/regarding ALTER TABLE, and could only find errors regarding this when
Microsoft was involved ;-)

Yeah, I feel sorry for those who rely on M$, but that's another topic.

I have thought of this...
...but isn't there a function in MySQL or PHP to retrieve the absolute recordnr of a db???

...if there is not, then your code IS good, if you absolutelty need the functionality! :-)

This exchange has given some ideas. One way is to use a timestamp to step through the records with a counter that's external to the dB. That way the customer can see a sequential count, while the dB is just stepping through records via timestamp. I think I can sell that.

In any event, this exchange has helped me -- so, thanks to all.

tedd


--
--------------------------------------------------------------------------------
http://sperling.com

--- End Message ---
--- Begin Message ---
Hi Rob!

Rob wrote:

<?php
$doc = new DOMDocument("1.0");
$node = $doc->createElement("root");
$node->setAttribute("align", "left");
$doc->appendChild($node);
echo $doc->saveXML();
?>

Both ways are perfectly valid. $node and $newnode refer to the same object. It was written the 1st way to demonstrate the return value of appendChild(), because in many cases people create the element differently.

i.e.

$newnode = $doc->appendChild($doc->createElement("root"));
or
$newnode = $doc->appendChild(new DOMElement("root"));

Thank you very much for confirming that! I was not sure if it's really the same.

Also, in the event $node is created using the new DOMElement syntax:

$node = new DOMElement("root");

the node is read only and must be appended into the tree before it can be modified, so the example just tries to be neutral here regarding the syntax used.

$node = new DOMElement("root");

is read only, while

$node = $doc->createElement("root");

is not? Why?


btw., I think this: http://news.php.net/php.internals/22117 is a very, very, very good idea! I hope the patch will make it into core soon!


best regards
Andreas

--- End Message ---
--- Begin Message ---
Andreas Korthaus wrote:

$node = new DOMElement("root");

is read only, while

$node = $doc->createElement("root");

is not? Why?

$node = new DOMElement("root");
In this case the element is not associated with a document. In DOM, you really aren't supposed to have a node not associated with any document, but this syntax allows the DOM classes to be extended in PHP. Once the node is associated with a document, you then have full editing capabilities.

Rob

--- End Message ---
--- Begin Message ---
chris smith wrote:

> >
> > So at some point the $auction_parts['id'] is empty.
> >
> > As you go into the loop, print out the $auction_house["id"], then work
> > backwards...
> >   
>   
I output already some variables in the loop and all are set with correct
values.
As I said, if I do the bind_param inside the loop it works without
problems. So there's a difference in doing it before the loop and inside
the loop causing this problem.


-- Regards Julius Hacker http://www.julius-hacker.de
[EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E

--- End Message ---
--- Begin Message ---
On Sun, Mar 05, 2006 at 04:03:17AM +0100, Julius Hacker wrote:
> > On 3/4/06, Julius Hacker <[EMAIL PROTECTED]> wrote:
> >   
> >>>
> >>> Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and
> >>> mysql_stmt_bind_param.
> >>> In the foreach-loop I give the variables, which I bound with bind_param,
> >>> their values and want to execute the statement.
> >>>
> >>> But now MySQL returns always an error.
> >>> It seems that the values I gave the variables in the loop aren't used
> >>> because I used bind_param before that.
> >>>
> >>> In the example for mysql_bind_param they do it like me.
> >>> Is the example also wrong or do I have to consider something special?
> >>>
> ...
> >   
> MySQL returns "Column 'auction_house' cannot be null".
> Here're some parts of my code:
> 
> --- code ---
> ...
>
> $insert = $this->sql->stmt_init();
> $insert->prepare("INSERT INTO auctions (auction_house, name, link,
> prize, runtime, bids, picture) VALUES (?, ?, ?, ?, ?, ?, ?)");
> $insert->bind_param("issdsis", $auction_house["id"],
> $auction_parts["name"], $auction_parts["link"], $auction_parts["prize"],
> $auction_parts["runtime"], $auction_parts["bids"],
> $auction_parts["picture"]);
> 
> --- /code ---

I assume your loop is something like:
  while(condition) {
    $auction_parts['id'] = 'some value';
    $auction_parts['name'] = 'some value';
    ...
    $insert->execute();
  }

My first guess would be, if not aleady done, initialize
$auction_parts before you do your bind_param() with something like:

  $auction_parts = array('id' => null, 'name' => null, ...);
  $insert->bind_param("issdsis", $auction_house["id"], ...);


Curt.
-- 
cat .signature: No such file or directory

--- End Message ---
--- Begin Message ---
On 3/5/06, Curt Zirzow <[EMAIL PROTECTED]> wrote:
> On Sun, Mar 05, 2006 at 04:03:17AM +0100, Julius Hacker wrote:
> > > On 3/4/06, Julius Hacker <[EMAIL PROTECTED]> wrote:
> > >
> > >>>
> > >>> Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and
> > >>> mysql_stmt_bind_param.
> > >>> In the foreach-loop I give the variables, which I bound with bind_param,
> > >>> their values and want to execute the statement.
> > >>>
> > >>> But now MySQL returns always an error.
> > >>> It seems that the values I gave the variables in the loop aren't used
> > >>> because I used bind_param before that.
> > >>>
> > >>> In the example for mysql_bind_param they do it like me.
> > >>> Is the example also wrong or do I have to consider something special?
> > >>>
> > ...
> > >
> > MySQL returns "Column 'auction_house' cannot be null".
> > Here're some parts of my code:
> >
> > --- code ---
> > ...
> >
> > $insert = $this->sql->stmt_init();
> > $insert->prepare("INSERT INTO auctions (auction_house, name, link,
> > prize, runtime, bids, picture) VALUES (?, ?, ?, ?, ?, ?, ?)");
> > $insert->bind_param("issdsis", $auction_house["id"],
> > $auction_parts["name"], $auction_parts["link"], $auction_parts["prize"],
> > $auction_parts["runtime"], $auction_parts["bids"],
> > $auction_parts["picture"]);
> >
> > --- /code ---
>
> I assume your loop is something like:
>   while(condition) {
>     $auction_parts['id'] = 'some value';
>     $auction_parts['name'] = 'some value';
>     ...
>     $insert->execute();
>   }
>
> My first guess would be, if not aleady done, initialize
> $auction_parts before you do your bind_param() with something like:
>
>   $auction_parts = array('id' => null, 'name' => null, ...);
>   $insert->bind_param("issdsis", $auction_house["id"], ...);
>
>
> Curt.
> --
> cat .signature: No such file or directory
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
might want to read up on bind_param. I'ts been awhile since I did this in Perl.


--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

--- End Message ---
--- Begin Message ---
Maybe I'm being hypocritic, and possibly wouldn't have this problem, if it
was a job that only EU Citizens(as opposed to only US Citizens) could apply
for, but I think it's a bit disrespectful, sending mails like this to an
international audience - especially when you send so many of them.

On 3/5/06, Beau Gould <[EMAIL PROTECTED]> wrote:
>
> LAMP Developers, Los Angeles | 70-120k
>
> LAMP Developers needed at all skill levels for multiple Los Angeles
> clients for full time, on-site jobs ranging from 70-120k + full benefits.
>
> Candidates must be authorized to work in the United States and be local to
> the Los Angeles, CA area.
>
> * At least 2 years of professional PHP web development experience
> * Good to expert knowledge of PHP, including knowledge of OO programming a
> plus
> * Strong experience with MySQL/SQL and creating database schemas.
> * Experience with HTML, CSS and JavaScript.
> * Knowledge of Unix/Linux.
> * Knowledge of Apache web server.
>
> Please send resume and full time salary requirements to
> [EMAIL PROTECTED]
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.375 / Virus Database: 268.1.2/274 - Release Date: 3/3/2006
>
>
> --
> PHP General Mailing List ( http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Job postings dont really belong on this list, expecially ones that
appear on a regular basis for a paticular company. 

Consider what would happen if sites like dice.org, monster.com,
etc...  started posting positions that matched the keyword 'php'
on a regular basis.

Curt.

On Sun, Mar 05, 2006 at 06:56:52PM +0100, Rory Browne wrote:
> Maybe I'm being hypocritic, and possibly wouldn't have this problem, if it
> was a job that only EU Citizens(as opposed to only US Citizens) could apply
> for, but I think it's a bit disrespectful, sending mails like this to an
> international audience - especially when you send so many of them.
> 
> On 3/5/06, Beau Gould <[EMAIL PROTECTED]> wrote:
> >
> > LAMP Developers, Los Angeles | 70-120k
> >
> > LAMP Developers needed at all skill levels for multiple Los Angeles
> > clients for full time, on-site jobs ranging from 70-120k + full benefits.
> >
> > Candidates must be authorized to work in the United States and be local to
> > the Los Angeles, CA area.
> >
> > * At least 2 years of professional PHP web development experience
> > * Good to expert knowledge of PHP, including knowledge of OO programming a
> > plus
> > * Strong experience with MySQL/SQL and creating database schemas.
> > * Experience with HTML, CSS and JavaScript.
> > * Knowledge of Unix/Linux.
> > * Knowledge of Apache web server.
> >

--- End Message ---
--- Begin Message ---
I'm thinking of getting an iBook for reasons not really to do with webbing but really need to do occasional php/mysql stuff to justify the expense. I believe that they all come with an Apache testing server installed and wondered if anyone had any success with getting php/mysql/phpMyAdmin working on one of these machines.

No problem at all. Mac OS X comes with PHP installed (but not activated). There are precompiled binaries of both PHP and MySQL available from www.entropy.ch and mysql.com, respectively. phpMyAdmin runs on anything that can run PHP and MySQL. No problem at all!

Larry

--- End Message ---
--- Begin Message ---
Hi Rob!

Rob wrote:
$node = new DOMElement("root");
In this case the element is not associated with a document. In DOM, you really aren't supposed to have a node not associated with any document, but this syntax allows the DOM classes to be extended in PHP. Once the node is associated with a document, you then have full editing capabilities.

Again, very helpful information - thanks a lot!

I have to do something like:

<?php

$array_of_book_objects = array('...');

$doc = new DOMDocument('1.0');
$books = $doc->appendChild(new DOMElement('books'));

foreach($array_of_book_objects as $book_data) {
  $book = $books->appendChild(new DOMElement('book'));
  $book->setAttribute('isbn', xml_entity_encode($book_data->isbn));
  $book->appendChild(new DOMElement('title',
    xml_entity_encode($book_data->title)));
  $book->appendChild(new DOMElement('description',
    xml_entity_encode($book_data->description)));
  $author = $book->appendChild(new DOMElement('author'));
  $author->appendChild(new DOMElement('name',
    xml_entity_encode($book_data->author_name)));
}
echo $doc->saveXML();
?>

Because my script is by far more complex (but does not use more advanced DOM features), I'd like to simplify the DOM api a little bit more. With extending DOMElement I think I have found a nice way:

<?php

class SimpleDOMElement extends DOMElement {

  function addChild($name, $value=NULL) {
    if (is_null($value)) {
      return $this->appendChild(new SimpleDOMElement($name));
    }
    else {
      return $this->appendChild(new SimpleDOMElement($name,
        xml_entity_encode($value)));
    }
  }

  function addAttribute($name, $value) {
    return $this->setAttribute($name, xml_entity_encode($value));
  }
}

class Books extends DOMDocument {

  private $books_element;

  function __construct() {
    parent::__construct('1.0');
    $this->books_element = $this->appendChild(
      new SimpleDOMElement('books'));
  }

  function addBook($book_object) {
    $book = $this->books_element->addChild('book');
    $book->addAttribute('isbn', $book_object->isbn);
    $book->addChild('title', $book_object->title);
    $book->addChild('description', $book_object->description);
    $author = $book->addChild('author');
    $author->addChild('name', $book_object->author_name);
  }
}

$array_of_book_objects = array('...');

$books = new Books;

foreach ($array_of_book_objects as $book_data) {
  $books->addBook($book_data);
}
echo $books->saveXML();
?>


I think this should be OK, or shouldn't I do it this way?


Perhaps you have seen that I've used a "xml_entity_encode()" function. This function works like htmlspecialchars(), but replaces ' with &apos; and not &#039;. Or do all of you use htmlspecialchars()? Does it work with Unicode strings?


best regards
Andreas

--- End Message ---
--- Begin Message ---
I have a page that resizes an image to be included in a html page, using:

echo "<img src=\"$rel_mapfile\"  alt=\"Course Map\">\n";

unlink($rel_mapfile);

I need the other html stuff on the page so I need to fetch a file from the 
server to include in the page.

So, I resized the image and saved it as a file.  That works fine.

After sending the temporary resized file I want to delete it.

Obviously, an unlink($rel_mapfile) is executed before the echo "<img 
src=\"$rel_mapfile\" ... is finished.

Thanks....

--- End Message ---
--- Begin Message --- I don't think you can. Each element in a web page is transmited over a separate connection, when the browser parses an included element, such as an image, an iframe, a stylesheet, an included script file or whatever, it opens a new connection to the server (or another server in the same domain) and from then on, they run completely asychronous, any of them can finish at any time, depending on many factors completely out of you control (such as caching so that an element might be taken from the local cache instead of picked from the server, which wouldn't be the case with dinamically generated images as your situation, but I mention it just as an example).

So, the answer to the question in the subject line is no, you cannot, the thread serving your main HTML document might end before the server even started serving the included image, or the other way around, and once your script if finished, you have no further control. Holding your script until the image is served might get it hang forever, since the image might not even be requested, if taken from the browser cache on the client side, so you might be waiting forever.

If you want to clean up dynamically generated files, you have to do it via a cron job every so often. Another alternative is serving the included images via a separate script, thus you would have to have:

echo '<img src="imageserver.php?img=' , urlencode($rel_mapfile) , '" alt="Course Map">' , CRLF;

Then imageserver.php would pick the image, serve it and when it is finished you delete it, nevertheless, this takes more CPU time, so I would still take the other option.

If you can attach a script to the end of a session, and you put all dynamically generated content under a directory named after the SessionId, when the session is over, you delete the complete directory with everything it had. (I know IIS does that, but I never had to manage an Apache server, someone can help on that?). This one doesn't take any overhead on a per-page basis, just once per session and keeps the disk storage clean.

Just some sugestions, I hope they help.

Satyam


----- Original Message ----- From: "Al" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, March 05, 2006 9:17 PM
Subject: [PHP] How can I tell if an output stream is finished?


I have a page that resizes an image to be included in a html page, using:

echo "<img src=\"$rel_mapfile\"  alt=\"Course Map\">\n";

unlink($rel_mapfile);

I need the other html stuff on the page so I need to fetch a file from the server to include in the page.

So, I resized the image and saved it as a file.  That works fine.

After sending the temporary resized file I want to delete it.

Obviously, an unlink($rel_mapfile) is executed before the echo "<img src=\"$rel_mapfile\" ... is finished.

Thanks....

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--- End Message ---
--- Begin Message ---
Many thinks for your input...

The sessions approach seems like a good one.

Since posting my question, I thought of writing the file in a tmp dir and using 
it.

Then scan the tmp dir for all files older than an hour or so and unlinking them. Sorta like a cron job without the extra effort.

Our site has a low usage so there will never be many obsolete files in the temp 
dir.

Again, thanks........

Satyam wrote:
I don't think you can. Each element in a web page is transmited over a separate connection, when the browser parses an included element, such as an image, an iframe, a stylesheet, an included script file or whatever, it opens a new connection to the server (or another server in the same domain) and from then on, they run completely asychronous, any of them can finish at any time, depending on many factors completely out of you control (such as caching so that an element might be taken from the local cache instead of picked from the server, which wouldn't be the case with dinamically generated images as your situation, but I mention it just as an example).

So, the answer to the question in the subject line is no, you cannot, the thread serving your main HTML document might end before the server even started serving the included image, or the other way around, and once your script if finished, you have no further control. Holding your script until the image is served might get it hang forever, since the image might not even be requested, if taken from the browser cache on the client side, so you might be waiting forever.

If you want to clean up dynamically generated files, you have to do it via a cron job every so often. Another alternative is serving the included images via a separate script, thus you would have to have:

echo '<img src="imageserver.php?img=' , urlencode($rel_mapfile) , '" alt="Course Map">' , CRLF;

Then imageserver.php would pick the image, serve it and when it is finished you delete it, nevertheless, this takes more CPU time, so I would still take the other option.

If you can attach a script to the end of a session, and you put all dynamically generated content under a directory named after the SessionId, when the session is over, you delete the complete directory with everything it had. (I know IIS does that, but I never had to manage an Apache server, someone can help on that?). This one doesn't take any overhead on a per-page basis, just once per session and keeps the disk storage clean.

Just some sugestions, I hope they help.

Satyam


----- Original Message ----- From: "Al" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, March 05, 2006 9:17 PM
Subject: [PHP] How can I tell if an output stream is finished?


I have a page that resizes an image to be included in a html page, using:

echo "<img src=\"$rel_mapfile\"  alt=\"Course Map\">\n";

unlink($rel_mapfile);

I need the other html stuff on the page so I need to fetch a file from the server to include in the page.

So, I resized the image and saved it as a file.  That works fine.

After sending the temporary resized file I want to delete it.

Obviously, an unlink($rel_mapfile) is executed before the echo "<img src=\"$rel_mapfile\" ... is finished.

Thanks....

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--- End Message ---
--- Begin Message ---
Al wrote:
I have a page that resizes an image to be included in a html page, using:

echo "<img src=\"$rel_mapfile\"  alt=\"Course Map\">\n";

unlink($rel_mapfile);

I need the other html stuff on the page so I need to fetch a file from the server to include in the page.

So, I resized the image and saved it as a file.  That works fine.

After sending the temporary resized file I want to delete it.

Obviously, an unlink($rel_mapfile) is executed before the echo "<img src=\"$rel_mapfile\" ... is finished.

Thanks....
Use flush();

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

--- End Message ---
--- Begin Message ---
Hi!

The XML-Code I have to create (http://news.php.net/php.general/231486), needs a root-element, with xmlns and XML schema link, something like that:

<Test xmlns="http://example.com/test";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://example.com/test
  test.xsd">

Does DOM provide any means to add a XML schema link to the doc?

Now I'm doing it this way (which seems to work):

<?php
$doc = new DOMDocument;
$root = $doc->appendChild(new DOMElement('root', NULL,
  'http://example.com/test'));
$root->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance',
  'xsi:schemaLocation', 'http://example.com/test test.xsd');
echo $doc->savexml();
?>

Does DOM provide nothing else?
Does anybody see any problems with this approach?


Best regards
Andreas

--- End Message ---

Reply via email to