0

I want to do is when a user fill a valid email in the textbox and click the send button it will send to his email his password directly.

My problem is the result takes 3 secs or more in order the ajax script receives the result specially when the php echo 0 to ajax. Does anyone know how to make my code faster?

  • 3
    Have you tried actually [measuring](http://stackoverflow.com/questions/1200214/how-can-i-measure-the-speed-of-code-written-in-php) where there time is spent? – leo Aug 16 '14 at 16:25
  • 1
    Someone call security, we've got a plaintext offender. – ArtOfCode Aug 16 '14 at 16:35
  • 1
    On a serious note, **don't** send out passwords in plain text. See plaintextoffenders.com and [this article](http://krebsonsecurity.com/2012/06/naming-and-shaming-the-plaintext-offenders/) – ArtOfCode Aug 16 '14 at 16:36
  • 1
    Are you using Windows and it yes with which address are you connecting to MySQL. – Kubuxu Aug 16 '14 at 17:53

3 Answers3

0

Make your connection persistent using mysql_pconnect.

Return only changed data and apply the difference instead of returning whole set of data.

Also, instead of hitting database often, you can cache as much as you can.

Also, refer to PHP micro-optimization tips.

Earth
  • 3,477
  • 6
  • 37
  • 78
0

Asynchronous request doesn't mean the request are fast, it means you can continue with your code flow without waiting for the response.

Running a query on your database and sending a mail will take time.

meda
  • 45,103
  • 14
  • 92
  • 122
  • But 3 seconds is a lot. People start spam buttons if they do not get response in 2 seconds. – Kubuxu Aug 16 '14 at 18:05
  • @user3934676, that is why you need to disable the 'submit button' until the 'asynchronous' request is complete. And, provide some 'feedback' so that people will wait for more than two seconds. – Ryan Vincent Aug 22 '14 at 15:02
0

The problem might be not in your ajax code.

Not really know how many records in table tbl_mkash. For a lot number of records (million of records) indexing field elog_email might speed up the query.

Glenn S
  • 1
  • 1