I don't think you can do much on the PHP-side. The latency is hard to
reduce because people can be accessing your site from anywhere in the
world. This is more of a user experience thing. You can (1) add some
kind of 'loading' image to show that something's processing, or you
can (2) fake the product count.

1) Using a loading indicator will ease the transition that your system
is doing something and will not make the slowness look as bad.
2) By faking it, I mean doing a client-side count. Instead of doing
the append after the AJAX response, doing it outside immediately after
the user selects/de-selects the checkbox. This way the user has an
immediate response of the updated item count. The issue with this is
that if the AJAX does fail due to network issues or something, the
actual count saved in the session will become unmatched with the
number listed on the page. However, this can be remedied if your
script can do periodic AJAX checks with the session to make sure
(using setInterval()) and update with the correct count accordingly.

Otherwise, if it's not critical for you to store the selected product
in the session via PHP, maybe you should store the info in the user's
cookies directly on the client-side with Javascript instead. This
reduces the hits to the server also with less AJAX calls.

On Feb 27, 12:16 am, heohni <heidi.anselstet...@consultingteam.de>
wrote:
> I see..
>
> But is this normal?
> I do not have any database queries in these ajax files.
> Only session handling.
>
> For example to add the prouct and to check the array size:
>
> if(!$_POST['ver_id'] && isset($_POST['postdata'])){
>         $verids = explode(",",$_POST['postdata']);
>         foreach($verids as $ver_id){
>                 if(is_numeric($ver_id))$_SESSION['checked_products'][$ver_id] 
> =
> $ver_id;
>         }}else{
>
>         if(is_numeric($_POST['ver_id']))$_SESSION['checked_products'][$_POST
> ['ver_id']] = $_POST['ver_id'];
>
> }
>
> // delete double id's
> if(is_array($_SESSION['checked_products']))$_SESSION
> ['checked_products'] = array_unique($_SESSION['checked_products']);
>
> if (is_array($_SESSION['checked_products']) && count($_SESSION
> ['checked_products']) > 0){
>         echo count($_SESSION['checked_products']);
>
> }else{
>         echo 0;
> }
>
> and to delete products from the session:
> if(!$_POST['ver_id'] && $_POST['postdata']){
>         $verids = explode(",",$_POST['postdata']);
>         foreach($verids as $ver_id){
>                 if(is_numeric($ver_id))unset($_SESSION['checked_products']
> [$ver_id]);
>         }}else{
>
>         if(is_numeric($_POST['ver_id']))unset($_SESSION['checked_products']
> [$_POST['ver_id']]);
>
> }
>
> if(count($_SESSION['checked_products']) == 0) unset($_SESSION
> ['checked_products']);
>
> So really nothing special,or?
> What can I do to speed it up? Any ideas?
>
> Thanks!
>
> On 26 Feb., 19:17, James <james.gp....@gmail.com> wrote:
>
> > I don't think it's the append that's taking long. It seems more like
> > the AJAX request and response (which might differ depending on your
> > location, of course) that's holding things up.
> > Here's what's happening for me. Everytime I click on a checkbox, an
> > AJAX call is made to:
> > ajax_unselected_products_from_session.php?singleevent
> > this request took about 450ms to 650ms for me.
> > immediately afterward, another AJAX call is made to:
> > ajax_add_selected_product_to_session.php?global_check
> > which takes an average of about 450ms for me. Then upon response of
> > that, your append is executed.
>
> > This means that upon clicking your checkbox, it does 2 AJAX calls that
> > takes approximately a second to complete, then it updates your text.
>
> > On Feb 26, 4:15 am,heohni<heidi.anselstet...@consultingteam.de>
> > wrote:
>
> > > Hi,
>
> > > I have this function build:
>
> > > $.ajax({
> > >                         type: "POST",
> > >                         url: 
> > > "/ajax_add_selected_product_to_session.php?global_check",
> > >                         success: function(msg){
> > >                                 /* add here what to do on success */
> > >                                 //alert(msg);
> > >                                 howmanyfromsession =  msg;
>
> > >                                 if (howmanyfromsession == 1){
> > >                                         $(".amount").empty();
> > >                                         $(".amount").append(' (Derzeit 
> > > ist ' + howmanyfromsession + '
> > > Produkt vorgemerkt)');
> > >                                 }else if(howmanyfromsession > 1){
> > >                                         $(".amount").empty();
> > >                                         $(".amount").append(' (Derzeit 
> > > sind ' + howmanyfromsession + '
> > > Produkte vorgemerkt)');
> > >                                 }else if(howmanyfromsession == 0){
> > >                                         $(".amount").empty();
> > >                                 }
>
> > >                                 if(howmanyonpage == 0 && 
> > > howmanyfromsession == 0) {
> > >                                 //alert('None are checked on page');
> > >                                         
> > > $(".requestbutton").attr("disabled", "disabled");
> > >                                 }else if(howmanyonpage == 0 && 
> > > howmanyfromsession > 0){
> > >                                         //alert('At least one is 
> > > checked');
> > >                                         
> > > $(".requestbutton").removeAttr("disabled");
> > >                                         
> > > $(".requestbutton").click(function(){
> > >                                                 $("#list").submit();
> > >                                         });
> > >                                 }
>
> > >                                 $(".requestbutton").click(function(){
> > >                                         
> > > if($("input[name^='paradigm']:checked").length > 0) {
> > >                                                 $("#list").submit();
> > >                                         }
> > >                                 });
> > >                         }
>
> > > The part with:
> > > $(".amount").append(' (Derzeit ist ' + howmanyfromsession + ' Produkt
> > > vorgemerkt)');
> > > takes really long at the moment. Is there a way to improve the speed?
> > > If you want you can test it 
> > > here:http://packpilot.s15312582.onlinehome-server.info/search.php?action=l...
> > > Look for the button "Für ausgewählte Artikel Herstelleranfrage senden"
> > > on its right hand side a small text will appear, telling how many
> > > products you have selected.
> > > I don't understand why it takles so long...?
>
> > > Any ideas?
>
>

Reply via email to