|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On July 25 2013 02:55 tec27 wrote: Decent programmers are not going to say "I like python" and think that's a good reason for choosing it for a project. If your company doesn't trust you to be able to pick the right tool for the job, they think you're a moron and unless you actually believe you are a moron, you should find a new job. Its really not that difficult.
There are plenty of companies that will treat you like shit, I'm not arguing that they don't exist. I'm just saying that if you have any self-respect and desire to actually work effectively, you shouldn't work for them. If you're in a position to be pitching project details to management before the project is confirmed, you're not exactly a low level programmer.
|
On July 25 2013 03:03 RoyGBiv_13 wrote:Show nested quote +On July 25 2013 02:55 tec27 wrote: Decent programmers are not going to say "I like python" and think that's a good reason for choosing it for a project. If your company doesn't trust you to be able to pick the right tool for the job, they think you're a moron and unless you actually believe you are a moron, you should find a new job. Its really not that difficult.
There are plenty of companies that will treat you like shit, I'm not arguing that they don't exist. I'm just saying that if you have any self-respect and desire to actually work effectively, you shouldn't work for them. +1 Programming is a creative profession. There's a ton of research on how to get the highest quality production out of a programmer. Agile methodologies have a pretty good track record of generating top notch code, while waterfall design is arguably the worst thing to happen to programming since PHP (har har har).
lol PHP is just comically weird
my favorite "feature" is that ternary operator is left associative and it causes things like this: $transport = 'T';
$vehicle = ( ( $transport == 'B' ) ? 'bus' : ( $transport == 'A' ) ? 'airplane' : ( $transport == 'T' ) ? 'train' : ( $transport == 'C' ) ? 'car' : ( $transport == 'H' ) ? 'horse' : 'feet' );
echo $vehicle;
this returns horse lol
|
Hyrule19173 Posts
That's because it's constructed wrong.
|
On July 25 2013 04:24 tofucake wrote: That's because it's constructed wrong.
well yeah. in php context it's wrong. in every other language with a ternary it would work "correctly"
|
Hi guys, i'd need some help from you, a couple of questions to be answered. A friend of mine has a project to do during holidays. She needs to low level format whole HDD (this means filling each byte with 0x0). And now it begins. It cannot show any dialog, so calling system("format c:/") is not an option. I've seen some codes in C++ but i'd prefer it to be C as i have it in school (basically whole theory covered so i only need experience and research) so i can understand your tips better. Is it even possible in C? In C++ i can try using CreateFile() and then ReadFile(), WriteFile() with HDD. But then i thought of bad sectors and it snared me. Any tips where i can start?
|
On July 25 2013 04:21 freelander wrote:Show nested quote +On July 25 2013 03:03 RoyGBiv_13 wrote:On July 25 2013 02:55 tec27 wrote: Decent programmers are not going to say "I like python" and think that's a good reason for choosing it for a project. If your company doesn't trust you to be able to pick the right tool for the job, they think you're a moron and unless you actually believe you are a moron, you should find a new job. Its really not that difficult.
There are plenty of companies that will treat you like shit, I'm not arguing that they don't exist. I'm just saying that if you have any self-respect and desire to actually work effectively, you shouldn't work for them. +1 Programming is a creative profession. There's a ton of research on how to get the highest quality production out of a programmer. Agile methodologies have a pretty good track record of generating top notch code, while waterfall design is arguably the worst thing to happen to programming since PHP (har har har). lol PHP is just comically weird my favorite "feature" is that ternary operator is left associative and it causes things like this: $transport = 'T';
$vehicle = ( ( $transport == 'B' ) ? 'bus' : ( $transport == 'A' ) ? 'airplane' : ( $transport == 'T' ) ? 'train' : ( $transport == 'C' ) ? 'car' : ( $transport == 'H' ) ? 'horse' : 'feet' );
echo $vehicle; this returns horse lol
That is PHP built in "if you stack multiple ternary, you deserve to die"-feature
|
I'm a java programmer by trade. For the past couple months, I've been working on my own project using PHP and Javascript with AJAX. It's going really well, but there are a lot of things that every commercial site has solved in PHP (like sessions timing out from the server) that I need to implement.
Is there a source online for a lot of these basic functions? I can find so much reference for Javascript and Jquery, but so little for PHP.
|
Hyrule19173 Posts
On July 25 2013 04:32 czaku wrote: Hi guys, i'd need some help from you, a couple of questions to be answered. A friend of mine has a project to do during holidays. She needs to low level format whole HDD (this means filling each byte with 0x0). And now it begins. It cannot show any dialog, so calling system("format c:/") is not an option. I've seen some codes in C++ but i'd prefer it to be C as i have it in school (basically whole theory covered so i only need experience and research) so i can understand your tips better. Is it even possible in C? In C++ i can try using CreateFile() and then ReadFile(), WriteFile() with HDD. But then i thought of bad sectors and it snared me. Any tips where i can start? Why?
|
On July 25 2013 04:50 fdsdfg wrote: I'm a java programmer by trade. For the past couple months, I've been working on my own project using PHP and Javascript with AJAX. It's going really well, but there are a lot of things that every commercial site has solved in PHP (like sessions timing out from the server) that I need to implement.
Is there a source online for a lot of these basic functions? I can find so much reference for Javascript and Jquery, but so little for PHP. http://php.net , which is maybe the best documentation of a language out there. But I assume that you already know that site, could you maybe describe your problem further. From what I understand you have e.g. a login system and you don't want that the user gets logged out, after the seesions has timed out. Thats normally solved by using cookies to recreate the sessions after it has timed out.
|
On July 25 2013 04:32 czaku wrote: Hi guys, i'd need some help from you, a couple of questions to be answered. A friend of mine has a project to do during holidays. She needs to low level format whole HDD (this means filling each byte with 0x0). And now it begins. It cannot show any dialog, so calling system("format c:/") is not an option. I've seen some codes in C++ but i'd prefer it to be C as i have it in school (basically whole theory covered so i only need experience and research) so i can understand your tips better. Is it even possible in C? In C++ i can try using CreateFile() and then ReadFile(), WriteFile() with HDD. But then i thought of bad sectors and it snared me. Any tips where i can start?
Just write a 1-line batch file that calls format and throws the output away. You're reinventing the wheel if you try to write a new format utility for no reason.
|
Hi, I have a question for the c++-gurus: given
template<class T = void> class foo { };
int main(void) { foo<> foo1; foo<int> foo2; } and that I am lazy, is there a way to makefoo foo1; foo<int> foo2; legal? I know i can do this
namespace detail { template<class T = void> class foo { }; } using foo = detail::foo<>;
int main(void) { foo foo1; detail::foo<int> foo2; } , but now i have to write detail:: for every class with a non-default template parameter. Is there any magic available to make this work, perhaps with template aliases?
|
On July 25 2013 04:57 Yoshi- wrote:Show nested quote +On July 25 2013 04:50 fdsdfg wrote: I'm a java programmer by trade. For the past couple months, I've been working on my own project using PHP and Javascript with AJAX. It's going really well, but there are a lot of things that every commercial site has solved in PHP (like sessions timing out from the server) that I need to implement.
Is there a source online for a lot of these basic functions? I can find so much reference for Javascript and Jquery, but so little for PHP. http://php.net , which is maybe the best documentation of a language out there. But I assume that you already know that site, could you maybe describe your problem further. From what I understand you have e.g. a login system and you don't want that the user gets logged out, after the seesions has timed out. Thats normally solved by using cookies to recreate the sessions after it has timed out.
There are a few things. Right now the session never times out, if I stay on a page forever, my client keeps sending AJAX to the server and getting a reply. He appears in 'users online' for days. I want his session terminated and his client redirected to the login page.
Same for a user who logs onto the site, closes the tab, and leaves his window open. When you open a new window, you are still logged in - I would like to see 'your session has timed out'.
It's easy to do this in theory - build a simple timestamp and kill the session if he tries to do something after it has expired. But the web industry has been doing this for a decade in pretty much the same way - it seems there really should be robust implementations that have been refined and optimized that I can leverage instead of reinventing.
I could say the same about a chat room, registering a user, etc. I feel like I'm adding every new feature like it's a school project instead of having some reference toward what is a correct, robust implementation.
|
@lukem
typedef could be your friend!
typedef foo<int> int_foo;
|
On July 25 2013 05:05 fdsdfg wrote:Show nested quote +On July 25 2013 04:57 Yoshi- wrote:On July 25 2013 04:50 fdsdfg wrote: I'm a java programmer by trade. For the past couple months, I've been working on my own project using PHP and Javascript with AJAX. It's going really well, but there are a lot of things that every commercial site has solved in PHP (like sessions timing out from the server) that I need to implement.
Is there a source online for a lot of these basic functions? I can find so much reference for Javascript and Jquery, but so little for PHP. http://php.net , which is maybe the best documentation of a language out there. But I assume that you already know that site, could you maybe describe your problem further. From what I understand you have e.g. a login system and you don't want that the user gets logged out, after the seesions has timed out. Thats normally solved by using cookies to recreate the sessions after it has timed out. There are a few things. Right now the session never times out, if I stay on a page forever, my client keeps sending AJAX to the server and getting a reply. He appears in 'users online' for days. I want his session terminated and his client redirected to the login page. Same for a user who logs onto the site, closes the tab, and leaves his window open. When you open a new window, you are still logged in - I would like to see 'your session has timed out'. It's easy to do this in theory - build a simple timestamp and kill the session if he tries to do something after it has expired. But the web industry has been doing this for a decade in pretty much the same way - it seems there really should be robust implementations that have been refined and optimized that I can leverage instead of reinventing. I could say the same about a chat room, registering a user, etc. I feel like I'm adding every new feature like it's a school project instead of having some reference toward what is a correct, robust implementation.
Well, is there even any sense to keep sending AJAX request, that is not only insanely inefficient, also apparently quite useless? You could just say that it will only send a limited amount of requests.
|
On July 25 2013 04:54 tofucake wrote:Show nested quote +On July 25 2013 04:32 czaku wrote: Hi guys, i'd need some help from you, a couple of questions to be answered. A friend of mine has a project to do during holidays. She needs to low level format whole HDD (this means filling each byte with 0x0). And now it begins. It cannot show any dialog, so calling system("format c:/") is not an option. I've seen some codes in C++ but i'd prefer it to be C as i have it in school (basically whole theory covered so i only need experience and research) so i can understand your tips better. Is it even possible in C? In C++ i can try using CreateFile() and then ReadFile(), WriteFile() with HDD. But then i thought of bad sectors and it snared me. Any tips where i can start? Why?
It's a project to pass the next semester from programming and she is not interested in learning it. So she asked for my help. Basically you show the teacher code, explain how it works and you passed.
On July 25 2013 05:00 fdsdfg wrote:Show nested quote +On July 25 2013 04:32 czaku wrote: Hi guys, i'd need some help from you, a couple of questions to be answered. A friend of mine has a project to do during holidays. She needs to low level format whole HDD (this means filling each byte with 0x0). And now it begins. It cannot show any dialog, so calling system("format c:/") is not an option. I've seen some codes in C++ but i'd prefer it to be C as i have it in school (basically whole theory covered so i only need experience and research) so i can understand your tips better. Is it even possible in C? In C++ i can try using CreateFile() and then ReadFile(), WriteFile() with HDD. But then i thought of bad sectors and it snared me. Any tips where i can start? Just write a 1-line batch file that calls format and throws the output away. You're reinventing the wheel if you try to write a new format utility for no reason.
The problem is it has to be in C/C++ and i prefer C at the moment.
|
Hyrule19173 Posts
On July 25 2013 05:05 fdsdfg wrote:Show nested quote +On July 25 2013 04:57 Yoshi- wrote:On July 25 2013 04:50 fdsdfg wrote: I'm a java programmer by trade. For the past couple months, I've been working on my own project using PHP and Javascript with AJAX. It's going really well, but there are a lot of things that every commercial site has solved in PHP (like sessions timing out from the server) that I need to implement.
Is there a source online for a lot of these basic functions? I can find so much reference for Javascript and Jquery, but so little for PHP. http://php.net , which is maybe the best documentation of a language out there. But I assume that you already know that site, could you maybe describe your problem further. From what I understand you have e.g. a login system and you don't want that the user gets logged out, after the seesions has timed out. Thats normally solved by using cookies to recreate the sessions after it has timed out. There are a few things. Right now the session never times out, if I stay on a page forever, my client keeps sending AJAX to the server and getting a reply. He appears in 'users online' for days. I want his session terminated and his client redirected to the login page. Same for a user who logs onto the site, closes the tab, and leaves his window open. When you open a new window, you are still logged in - I would like to see 'your session has timed out'. It's easy to do this in theory - build a simple timestamp and kill the session if he tries to do something after it has expired. But the web industry has been doing this for a decade in pretty much the same way - it seems there really should be robust implementations that have been refined and optimized that I can leverage instead of reinventing. I could say the same about a chat room, registering a user, etc. I feel like I'm adding every new feature like it's a school project instead of having some reference toward what is a correct, robust implementation. The simple solution is to just use the session itself. Set $_SESSION['lastactivitytimestamporwhatetever'] when a user goes to a page, but not on ajax calls. If it's above some threshhold clear the session and redirect to login.
|
On July 25 2013 05:12 czaku wrote:Show nested quote +On July 25 2013 04:54 tofucake wrote:On July 25 2013 04:32 czaku wrote: Hi guys, i'd need some help from you, a couple of questions to be answered. A friend of mine has a project to do during holidays. She needs to low level format whole HDD (this means filling each byte with 0x0). And now it begins. It cannot show any dialog, so calling system("format c:/") is not an option. I've seen some codes in C++ but i'd prefer it to be C as i have it in school (basically whole theory covered so i only need experience and research) so i can understand your tips better. Is it even possible in C? In C++ i can try using CreateFile() and then ReadFile(), WriteFile() with HDD. But then i thought of bad sectors and it snared me. Any tips where i can start? Why? It's a project to pass the next semester from programming and she is not interested in learning it. So she asked for my help. Basically you show the teacher code, explain how it works and you passed. Show nested quote +On July 25 2013 05:00 fdsdfg wrote:On July 25 2013 04:32 czaku wrote: Hi guys, i'd need some help from you, a couple of questions to be answered. A friend of mine has a project to do during holidays. She needs to low level format whole HDD (this means filling each byte with 0x0). And now it begins. It cannot show any dialog, so calling system("format c:/") is not an option. I've seen some codes in C++ but i'd prefer it to be C as i have it in school (basically whole theory covered so i only need experience and research) so i can understand your tips better. Is it even possible in C? In C++ i can try using CreateFile() and then ReadFile(), WriteFile() with HDD. But then i thought of bad sectors and it snared me. Any tips where i can start? Just write a 1-line batch file that calls format and throws the output away. You're reinventing the wheel if you try to write a new format utility for no reason. The problem is it has to be in C/C++ and i prefer C at the moment.
You're asking for help on writing your friend's school project for her? She should fail if she can't learn the stuff. Programmers work on teams, and I wouldn't wish a useless teammate on any fellow programmer, which is what you're trying to inflict.
On July 25 2013 05:11 Yoshi- wrote:Show nested quote +On July 25 2013 05:05 fdsdfg wrote:On July 25 2013 04:57 Yoshi- wrote:On July 25 2013 04:50 fdsdfg wrote: I'm a java programmer by trade. For the past couple months, I've been working on my own project using PHP and Javascript with AJAX. It's going really well, but there are a lot of things that every commercial site has solved in PHP (like sessions timing out from the server) that I need to implement.
Is there a source online for a lot of these basic functions? I can find so much reference for Javascript and Jquery, but so little for PHP. http://php.net , which is maybe the best documentation of a language out there. But I assume that you already know that site, could you maybe describe your problem further. From what I understand you have e.g. a login system and you don't want that the user gets logged out, after the seesions has timed out. Thats normally solved by using cookies to recreate the sessions after it has timed out. There are a few things. Right now the session never times out, if I stay on a page forever, my client keeps sending AJAX to the server and getting a reply. He appears in 'users online' for days. I want his session terminated and his client redirected to the login page. Same for a user who logs onto the site, closes the tab, and leaves his window open. When you open a new window, you are still logged in - I would like to see 'your session has timed out'. It's easy to do this in theory - build a simple timestamp and kill the session if he tries to do something after it has expired. But the web industry has been doing this for a decade in pretty much the same way - it seems there really should be robust implementations that have been refined and optimized that I can leverage instead of reinventing. I could say the same about a chat room, registering a user, etc. I feel like I'm adding every new feature like it's a school project instead of having some reference toward what is a correct, robust implementation. Well, is there even any sense to keep sending AJAX request, that is not only insanely inefficient, also apparently quite useless? You could just say that it will only send a limited amount of requests.
That comes from a chat interface - you have a chat room open and you're sending AJAX to the server to find out if there's any new messages or any new people in the chat lobby.
Also within the game (it's a turn-based game), you're polling the server to see if your opponent has submitted their turn yet.
These AJAX queries serve a distinct function, but when the user is away and has happened to leave his window open, they do not serve a function. I need to time him out.
Now I can write something that will time him out, but like I said, I want to do it in a clean and correct way. The industry has been doing this for a long time, so I'm sure the information is out there on the correct way to do something like this.
On July 25 2013 05:24 tofucake wrote: The simple solution is to just use the session itself. Set $_SESSION['lastactivitytimestamporwhatetever'] when a user goes to a page, but not on ajax calls. If it's above some threshhold clear the session and redirect to login.
Yeah, but I feel like this is something common enough where I don't need to just write a simple solution. It seems like enough people have done this exact thing so there should be thorough implementations floating around that I can use.
For instance, I have a 'dbhelper' class that handles a lot of communication with my database. I don't need to use 'mysql_connect' or 'mysql_fetch_assoc' - I have a framework that I simply call 'buildSelectObject($sql)' and it handles all error handling and whatnot. I can't seem to find such a framework for other things in PHP so I just code a 'dumb' version myself
|
On July 25 2013 05:05 fdsdfg wrote:Show nested quote +On July 25 2013 05:11 Yoshi- wrote:On July 25 2013 05:05 fdsdfg wrote:On July 25 2013 04:57 Yoshi- wrote:On July 25 2013 04:50 fdsdfg wrote: I'm a java programmer by trade. For the past couple months, I've been working on my own project using PHP and Javascript with AJAX. It's going really well, but there are a lot of things that every commercial site has solved in PHP (like sessions timing out from the server) that I need to implement.
Is there a source online for a lot of these basic functions? I can find so much reference for Javascript and Jquery, but so little for PHP. http://php.net , which is maybe the best documentation of a language out there. But I assume that you already know that site, could you maybe describe your problem further. From what I understand you have e.g. a login system and you don't want that the user gets logged out, after the seesions has timed out. Thats normally solved by using cookies to recreate the sessions after it has timed out. There are a few things. Right now the session never times out, if I stay on a page forever, my client keeps sending AJAX to the server and getting a reply. He appears in 'users online' for days. I want his session terminated and his client redirected to the login page. Same for a user who logs onto the site, closes the tab, and leaves his window open. When you open a new window, you are still logged in - I would like to see 'your session has timed out'. It's easy to do this in theory - build a simple timestamp and kill the session if he tries to do something after it has expired. But the web industry has been doing this for a decade in pretty much the same way - it seems there really should be robust implementations that have been refined and optimized that I can leverage instead of reinventing. I could say the same about a chat room, registering a user, etc. I feel like I'm adding every new feature like it's a school project instead of having some reference toward what is a correct, robust implementation. Well, is there even any sense to keep sending AJAX request, that is not only insanely inefficient, also apparently quite useless? You could just say that it will only send a limited amount of requests. That comes from a chat interface - you have a chat room open and you're sending AJAX to the server to find out if there's any new messages or any new people in the chat lobby. Also within the game (it's a turn-based game), you're polling the server to see if your opponent has submitted their turn yet. These AJAX queries serve a distinct function, but when the user is away and has happened to leave his window open, they do not serve a function. I need to time him out. Now I can write something that will time him out, but like I said, I want to do it in a clean and correct way. The industry has been doing this for a long time, so I'm sure the information is out there on the correct way to do something like this. There isn't really a proper way to do this, as the proper way to write a chat does not include AJAX. That is where you should use WebSockets.
And if you still want to do this the proper way, it would be that if a user hasn't used the chat in the last minutes, you would stop doing Ajax request and instead show a "You are now inactive in chat, click here to be active again" message, after you click on it the ajax request will continue.
|
On July 25 2013 05:40 Yoshi- wrote:Show nested quote +On July 25 2013 05:05 fdsdfg wrote:On July 25 2013 05:11 Yoshi- wrote:On July 25 2013 05:05 fdsdfg wrote:On July 25 2013 04:57 Yoshi- wrote:On July 25 2013 04:50 fdsdfg wrote: I'm a java programmer by trade. For the past couple months, I've been working on my own project using PHP and Javascript with AJAX. It's going really well, but there are a lot of things that every commercial site has solved in PHP (like sessions timing out from the server) that I need to implement.
Is there a source online for a lot of these basic functions? I can find so much reference for Javascript and Jquery, but so little for PHP. http://php.net , which is maybe the best documentation of a language out there. But I assume that you already know that site, could you maybe describe your problem further. From what I understand you have e.g. a login system and you don't want that the user gets logged out, after the seesions has timed out. Thats normally solved by using cookies to recreate the sessions after it has timed out. There are a few things. Right now the session never times out, if I stay on a page forever, my client keeps sending AJAX to the server and getting a reply. He appears in 'users online' for days. I want his session terminated and his client redirected to the login page. Same for a user who logs onto the site, closes the tab, and leaves his window open. When you open a new window, you are still logged in - I would like to see 'your session has timed out'. It's easy to do this in theory - build a simple timestamp and kill the session if he tries to do something after it has expired. But the web industry has been doing this for a decade in pretty much the same way - it seems there really should be robust implementations that have been refined and optimized that I can leverage instead of reinventing. I could say the same about a chat room, registering a user, etc. I feel like I'm adding every new feature like it's a school project instead of having some reference toward what is a correct, robust implementation. Well, is there even any sense to keep sending AJAX request, that is not only insanely inefficient, also apparently quite useless? You could just say that it will only send a limited amount of requests. That comes from a chat interface - you have a chat room open and you're sending AJAX to the server to find out if there's any new messages or any new people in the chat lobby. Also within the game (it's a turn-based game), you're polling the server to see if your opponent has submitted their turn yet. These AJAX queries serve a distinct function, but when the user is away and has happened to leave his window open, they do not serve a function. I need to time him out. Now I can write something that will time him out, but like I said, I want to do it in a clean and correct way. The industry has been doing this for a long time, so I'm sure the information is out there on the correct way to do something like this. There isn't really a proper way to do this, as the proper way to write a chat does not include either php or AJAX. That is where you should use WebSockets, which PHP doesn't support. And if you still want to do this the proper way, it would be that if a user hasn't used the chat in the last minutes, you would stop doing Ajax request and instead show a "You are now inactive in chat, click here to be active again" message, after you click on it the ajax request will continue.
Isn't google chat (chat from the gmail web interface) done using ajax?
|
Hyrule19173 Posts
On July 25 2013 05:40 Yoshi- wrote:Show nested quote +On July 25 2013 05:05 fdsdfg wrote:On July 25 2013 05:11 Yoshi- wrote:On July 25 2013 05:05 fdsdfg wrote:On July 25 2013 04:57 Yoshi- wrote:On July 25 2013 04:50 fdsdfg wrote: I'm a java programmer by trade. For the past couple months, I've been working on my own project using PHP and Javascript with AJAX. It's going really well, but there are a lot of things that every commercial site has solved in PHP (like sessions timing out from the server) that I need to implement.
Is there a source online for a lot of these basic functions? I can find so much reference for Javascript and Jquery, but so little for PHP. http://php.net , which is maybe the best documentation of a language out there. But I assume that you already know that site, could you maybe describe your problem further. From what I understand you have e.g. a login system and you don't want that the user gets logged out, after the seesions has timed out. Thats normally solved by using cookies to recreate the sessions after it has timed out. There are a few things. Right now the session never times out, if I stay on a page forever, my client keeps sending AJAX to the server and getting a reply. He appears in 'users online' for days. I want his session terminated and his client redirected to the login page. Same for a user who logs onto the site, closes the tab, and leaves his window open. When you open a new window, you are still logged in - I would like to see 'your session has timed out'. It's easy to do this in theory - build a simple timestamp and kill the session if he tries to do something after it has expired. But the web industry has been doing this for a decade in pretty much the same way - it seems there really should be robust implementations that have been refined and optimized that I can leverage instead of reinventing. I could say the same about a chat room, registering a user, etc. I feel like I'm adding every new feature like it's a school project instead of having some reference toward what is a correct, robust implementation. Well, is there even any sense to keep sending AJAX request, that is not only insanely inefficient, also apparently quite useless? You could just say that it will only send a limited amount of requests. That comes from a chat interface - you have a chat room open and you're sending AJAX to the server to find out if there's any new messages or any new people in the chat lobby. Also within the game (it's a turn-based game), you're polling the server to see if your opponent has submitted their turn yet. These AJAX queries serve a distinct function, but when the user is away and has happened to leave his window open, they do not serve a function. I need to time him out. Now I can write something that will time him out, but like I said, I want to do it in a clean and correct way. The industry has been doing this for a long time, so I'm sure the information is out there on the correct way to do something like this. There isn't really a proper way to do this, as the proper way to write a chat does not include either php or AJAX. That is where you should use WebSockets, which PHP doesn't support. And if you still want to do this the proper way, it would be that if a user hasn't used the chat in the last minutes, you would stop doing Ajax request and instead show a "You are now inactive in chat, click here to be active again" message, after you click on it the ajax request will continue. There are a bunch of php websocket libraries. socketo.me is probably the most well known. And even without that PHP still supports sockets (I made a bnet bot in php+ajax almost a decade ago).
|
|
|
|
|
|