php-general Digest 12 Feb 2006 15:32:36 -0000 Issue 3959

Topics (messages 230261 through 230266):

Asynchronous Processing
        230261 by: Gustavo Rios

Class/functions question
        230262 by: Paul Goepfert
        230264 by: M. Sokolewicz
        230265 by: Chris Shiflett

Re: Clone of the concurrent users limit of Zend Encoder 4.0 ?
        230263 by: HoWang Wang
        230266 by: Mark Charette

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 ---
Hey folks,

i am writing a small program in C that does mysql queries. The problem
i am facing is that it is done in synchronous fashion. I wonder how
php does mysql queries in asynchronous fashion?

Thanks for your time and cooperation.

Best regards.

--- End Message ---
--- Begin Message ---
Hi all,

I building a website with PHP.  I am going to be using functions to
deal with vaildation.  I am putting all the methods in a class called
Validation.  My problem is I do not know how to call the function. 
Well I shouldn't say that.  I know how to call functlions, I just just
don't know how to do it in PHP.  Let me put it this way.  When I write
programs in C++/Java I know that I have to do the following steps,

create an object reference to the class
use the object reference to access the methods.

I am almost certain that it is the same thing in PHP.  So this is what
I did in my web page.


<?php
if (isset($submit))
{
//validation code
class Validation
{
        function checkEmpty ($var)
        {
                if (empty($var))
                {
                        echo "YEAH It works!!";
                }
        }
}

else
{?>
.....
<tr>
        <td align="left">First Name</td>
        <td align="left">
                <span class="color">*</span><input type="text" name="name" 
size="20">
                <?php
                        $v = new Validation;
                        $v->checkEmpty($_POST["name"]);
                ?>
        </td>
</tr>
......

... = rest of php/html code

the else block holds the entire html code for the page

Do I have the logic right?

Paul

--- End Message ---
--- Begin Message ---
Paul Goepfert wrote:

Hi all,

I building a website with PHP.  I am going to be using functions to
deal with vaildation.  I am putting all the methods in a class called
Validation. My problem is I do not know how to call the function. Well I shouldn't say that. I know how to call functlions, I just just
don't know how to do it in PHP.  Let me put it this way.  When I write
programs in C++/Java I know that I have to do the following steps,

create an object reference to the class
use the object reference to access the methods.

I am almost certain that it is the same thing in PHP.  So this is what
I did in my web page.


<?php
if (isset($submit))
{
//validation code
class Validation
{
        function checkEmpty ($var)
        {
                if (empty($var))
                {
                        echo "YEAH It works!!";
                }
        }
}

else
{?>
.....
<tr>
        <td align="left">First Name</td>
        <td align="left">
                <span class="color">*</span><input type="text" name="name" 
size="20">
                <?php
                        $v = new Validation;
                        $v->checkEmpty($_POST["name"]);
                ?>
        </td>
</tr>
......

... = rest of php/html code

the else block holds the entire html code for the page

Do I have the logic right?

Paul


Yes and no. Yes, you're calling it correctly, and no because when submit is set, your php scipt will have a class called Validation, and no HTML is being sent to output. On the other hand, when submit is not set, you output a bunch of HTML, but never define your class, and thus will get a couple of errors from it.

- tul

--- End Message ---
--- Begin Message ---
Paul Goepfert wrote:
I know how to call functlions, I just just don't know how to
do it in PHP.

Based on the rest of your question, I think you mean methods, not functlions. :-)

If you're struggling with syntax, you should take one step at a time. Try this:

<?php

class myClass
{
    function myMethod()
    {
        echo '<p>myMethod()</p>';
    }
}

$myObject = new myClass;

$myObject->myMethod();

?>

That should help you with any syntax problems, but I suspect your problem has more to do with logic than with syntax.

if (isset($submit))
{
   class Validation
   {

/* ... */

   }
}
else
{

/* ... */

   $v = new Validation;
   $v->checkEmpty($_POST["name"]);

If the form is submitted, define the class, else use the class. That doesn't sound right...

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

--- End Message ---
--- Begin Message ---
Curt Zirzow wrote:
On Sat, Feb 11, 2006 at 12:48:50PM +0800, HoWang Wang wrote:

HoWang Wang wrote:

Hi all,

The Zend Encoder 4.0 (beta) have a new function in the license manager
which can limit the number of concurrent users. I have wriiten something
to work like it. But I found a problem. My script can limit the number
of concurrent running script only. When the script ends, there is some
data remain in the buffer (of Apache, I think) and the client connection
is still active! How can I solve this? Please help, Thanks.

Regards

Is it really impossible? Can I do it with Connection Handling?


It is really unclear on exactly what you are doing and i have no
clue what data is remaining in what buffer you think might be the
problem.

<?php
   set_time_limit(0);
   ignore_user_abort(true);
   // add 1 to the number of concurrent users
   // the rest of code
   while (!connection_aborted()) {
       // keep on locking
   } else {
       // release lock
   }
?>


You really dont want to do this. By doing that while loop, you will
do a couple of bad things:

   - eating up a lot of CPU usage, of course a sleep in the loop
     would probably prevent cpu abuse but still not the ideal way
     to do it.
   - You will most likely run out of available slots that http has
     available.


Curt.

Let me give an example:

on fileplanet.com, they have something so called "download slot" and "lines". They limit the number of concurrent downloads. If there are too many users, they will disallow new user to download their files. As I know, they do it with custom HTTP server.

PHP run very quickly & pass all contents to Apache within 0.000X second. But the web server usually have to take up 1 or more seconds to send all the contents to the client. Is it possible to limit the concurrent users (including the users receiving data but the php script already finished) with PHP?

Please reply, thanks to all.

Regards

--- End Message ---
--- Begin Message ---


Let me give an example:

on fileplanet.com, they have something so called "download slot" and "lines". They limit the number of concurrent downloads. If there are too many users, they will disallow new user to download their files. As I know, they do it with custom HTTP server.
Not so custom ... Apache has quite a few bandwidth limiting modules. I use mod_bandwidth to accomplish this.
--- End Message ---

Reply via email to