Forum Moderators: coopster

Message Too Old, No Replies

what is the best way to do this?

         

smagdy

10:47 am on Apr 1, 2006 (gmt 0)

10+ Year Member



Hello everybody,

1- The user will submit a form
2- I will compare that last_inserted_record with all records in a table
3- After the compare i will send email alerts to those who are equal?

My Questions are:
- Should i use JOIN to compare the records?
- I want to start the compare after the user submit the form, so should i use AJAX to compare in the background? or should i use cron jobs to compare every 15 min for example?(i dont recommend this)

Also when Ajax work in the background.. does it keep working even if the user closed his browser after the submit?

Thanks in advance

Anyango

5:38 am on Apr 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well why do you make it so tough for ya, both those options sound not necessary, atleast to me.

Whenever user submits a form, You just put that data in database and run a simple select query to findout matching records and then send email based on that.

smagdy

9:45 am on Apr 2, 2006 (gmt 0)

10+ Year Member



This is true, but what i think of is...

What if i had to send like 50 emails or something?

Then why should i let the user wait all that after he submits his form?

Thanks

jatar_k

3:07 pm on Apr 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you want to run something that isn't user instantiated then you should use a cron, I am not sure why you "dont recommend this".

smagdy

3:15 pm on Apr 2, 2006 (gmt 0)

10+ Year Member



Because "cron" is associated with time span but i want this job to be associated with "when someone submits a form"!

so if i did cron for example every 15min then maybe several people have submitted forms.. so it will be more compares and it could work lot of times when there is nothing to compare!

But if i did it just when the user submit, then that would be the best... so thats why am thinking of XMLHTTPREQUEST... but i need to hear your opinions first?

Thanks

jatar_k

7:30 pm on Apr 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well if you do it on user submit then you run the risk of it taking a long time

you could split the job up

do your select and compare on submit then write all your emails to file, then have a cron send them every couple of minutes or even quicker if you want.

smagdy

7:55 pm on Apr 2, 2006 (gmt 0)

10+ Year Member



Thanks,

Nice idea, i never thought of it cuz i never tried to use php to write to file...... but something new to learn!

Thanks again

smagdy

8:26 am on Apr 7, 2006 (gmt 0)

10+ Year Member



Hello again,

Thanks for your idea, i did it
"do your select and compare on submit then write all your emails to file..."

but i have 2 questions:

1. What will happen if more than 1 tried to write to the file? will it append or delete the old (which will destroy everything)

2. Why not insert the emails to MySQL, is it much faster to write to text files?

i mean if there is problem with txt files when more than 1 access it.. then the DB will be better solution.. or what?

Thanks in advance

gettopreacherman

3:29 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



You can do a couple of things, you can replace the file, or you can simply append the end of it. You could also try searching for a file called "new" and if it exists, append to it, if it doesn't create it.

Then when the cron runs, use it to send the email then when the cron ends, delete or move the file and there ya go.

Writing to file is just as easy as mySql...plus, if you don't want to hold on to old email updates, it's just as easy to blow away old files...don't need a db or anything, go with the flat file solution...

smagdy

3:52 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



but sometimes i will need to remove some lines from the text file which i did by using file(); to get the text into array..

am worrying about when several process want to access the file.. like adding data deleting and reading to send the email.....

the problem is that its hard to test accessing the file same time.. so i think it will be better off with DB, but am still willing to hear you!

Thanks

jatar_k

4:04 pm on Apr 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I used files since it fit what I need to do. Everytime the process was run it created a file for those emails. This file had a unique name. You can use 1 or many files.

The cron just has to make sure nothing messes with the file when it is running. You could have the cron change the name then delete the new file when it is done.

If you use multiple files then you can scan a certain directory and walk through one file at a time deleting as you go.

and the database route work too.

whatever works for you and your system is the way to go.

smagdy

4:19 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



Thanks a lot, but i just want to know is it much faster to write to file than to DB MySQL?

thanks

jatar_k

4:28 pm on Apr 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you'd have to test it, file is often faster but that all depends on what you are doing.

gettopreacherman

10:05 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



File is almost always faster, especially if they're named unique. You don't have to open and maintain a db connection...