views:

42

answers:

3

Alright I'm going to create a fairly complex form to post via AJAX a lot of different types of information PHP page which will then parse the data and CURL the various datatypes into the correct tables in another database.

Usually I just send a HUGE POST request and then parse the information in the PHP page, making multiple CURL requests along the way to post the various elements.

The downside is the form isn't super responsive, it generally takes 5-10 seconds for the PHP page to give the a-ok. I'd like this new form to be more snappy for better data entry, allowing the user to move onto the next entry without a hitch.

So just looking for some professional advice: Make 5 AJAX requests to 5 PHP pages or stick with the large load?

In terms of scale, there generally wont be many users it at the same time (it's internal for an organization), I'm trying to optimize for a single person submitting many entries over and over again with the same form.

Any and all advice is very welcome and appreciated.

A: 

On a webpage, where there are various fields, I tend to find it best to just send the data over as the users enter it, and jquery makes it easy with the event handling, so that if there is a problem the users can be informed quickly.

But, if the data must be processed as a group, for example, you have a 100x100 matrix and only when it is filled in can you do the mathematics, then one large post works.

So, it depends, if you can't validate until you have all the related information, for example, you don't know if an address is valid until you have street, city, state, then wait until all three are entered then submit the information.

Without more information as what is being done it is hard to really answer the question, but, as a rule of thumb, submit the smallest amount of information that is useful to give the fastest response back to the user if there is an error.

James Black
Unfortunately the data is kind of linked together, I'd also be worried about submitting half finished or incorrect data the user accidentally entered.
Mojowen
A: 

Hi,

PHP page which will then parse the data and CURL the various datatypes into the correct tables in another database.

Are you making an HTTP Request then? If yes, you should stick to one big AJAX call because otherwise you'd have to establish an HTTP Connection 5 times and establishing a connection takes time!

sled
Hadn't thought about that but it'd be 5 authentications, very annoying.
Mojowen
A: 

One thing to keep in mind: If you're using file-based sessions and those "5 posts" are all handled by the same site/server, you won't be able to have those 5 POSTs running in parallel. PHP will slap exclusive locks on the session file for each request, so they'll effectively be processed in a serial manner rather than parallel.

Unless you do a session_write_close() in each one, you'd be better off doing one big POST instead and save the extra overhead of establishing/tearing down 5 connections.

Marc B
Great point! I think from everything I've heard I'm definitely going to stick with a huge post.
Mojowen