I’m gonna level with you guys. I made a view tracker for my website in PHP and I’m chasing a really obscure bug where it wipes out all the accumulated views but it’s like one of those 1 in 5000 chance bugs so now I’m just uploading this here to try and accumulate some views so it might happen while I’m looking at it… Sorry; enjoy the picture

  • redline23@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    1 year ago

    That sounds like a possible race condition when multiple requests are executing at the same time. Without knowing anything about the design, perhaps you could look into database transactions. You could also look into generating load via jmeter, but then we wouldn’t get a picture.

    • drkt@feddit.dkOP
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      Using SQLite seems to have solved it, but it’s still bogged down by disk IO speeds. The only way I can induce errors right now is with benchmark tools, and that’ll be solved if I use an in-memory DB hopefully.

  • TWeaK@lemm.ee
    link
    fedilink
    English
    arrow-up
    4
    ·
    1 year ago

    Lmfao I didn’t scroll all the way before tapping and thought this was a blurred NSFW post.

  • JustinA
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    4
    ·
    1 year ago

    PHP is a very clunky language, even with the improvements in PHP 7 and 8. I would recommend Rust, Python, or Javascript for a backend instead.

    Also, I would recommend something like prometheus or opentelemetry for counting page views. Plenty of tooling available for those, you can even use them to count page views directly in nginx.

    • drkt@feddit.dkOP
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      PHP is a very clunky language, however it slots right into Apache with no fuzz and that’s very important. My Apache container needs to be as squeaky clean as possible. Rust and Python are not clean and JS doesn’t have the functionality I need without installing more stuff anyway.

      This is the only real issue I’ve ever had with PHP and it seems to have come down to me using a .txt file for a database and praying the underlying filesystem would just deal with it. It’s been swapped for SQLite and none of the counters were reset overnight. Presumably that was the issue, and is thus not the fault of PHP.

      • SorteKanin@feddit.dk
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        My Apache container needs to be as squeaky clean as possible. Rust and Python are not clean

        How is Rust not clean? You don’t need to install Rust in your container - just compile your program and put the binary in the container, no installation of anything else needed.

        • drkt@feddit.dkOP
          link
          fedilink
          arrow-up
          3
          ·
          1 year ago

          Because now I have to compile rust and cross-compiling from Windows to Linux is a mess I don’t wanna deal with. I don’t want to spin up a whole container just to compile for Linux.

          At any rate, the problem is solved and I’m just optimizing it for speed now, which is entirely disk IO so I’m converting it to using an in-memory DB and then it’ll be fast enough to handle a thousand times more traffic than I’ve ever gotten.

          I’m not a programmer, I’m just a photographer who doesn’t wanna deal with chunky gallery systems.

          • SorteKanin@feddit.dk
            link
            fedilink
            arrow-up
            2
            ·
            1 year ago

            Because now I have to compile rust and cross-compiling from Windows to Linux is a mess I don’t wanna deal with. I don’t want to spin up a whole container just to compile for Linux.

            That’s fair, though honestly cross-compiling Rust isn’t that hard. You could also just use Windows Subsystem for Linux to compile for Linux. But totally fair using whatever works for you of course.