Jump to content

holdorfold

Members
  • Posts

    25
  • Joined

  • Last visited

holdorfold's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I've made a test database from the book "PHP and mySQL Novice to Ninja"... now I'm testing out making the structure better by using templates to output the html. This is the template... note the part in with the arrow pointing to it. That's the dynamic content which should change based upon what page is passed to it. <!DOCTYPE html> <html lang="en"> <head> <link href= "/project/includes/style.css" rel="stylesheet" type="text/css"> <meta charset="utf-8"> <title>Joke Database Project</title> </head> <body> <div id="topheader"> <p>Joke Database Project</p> </div> <div id="navigation"> <?php include $_SERVER['DOCUMENT_ROOT'] .'/project/includes/navbar.html.php'; ?> </div> <div id="container"> <?php include '/'.$content;?> <<<<--------------------------------------- </div> </body> </html> It works fine when I use the following code in my php script: $content="authors.html.php"; include $_SERVER['DOCUMENT_ROOT'] . '/project/includes/html_template.html.php'; However I want to make it less clunky so I decided to create the following function include in my php script so I can show the relevant content by using showpage("author.html.php") function showpage($content) { include $_SERVER['DOCUMENT_ROOT'] . '/project/includes/html_template.html.php'; } The problem I'm having is when I use this function the outputed page no longer recognises the variables from the main script so the proper content doesn't show. (note it works fine when not using the function but just including it directly in the script). How can I get around this in an elegant way?
  2. In the end I contacted my hosting provider and had them look at it. Apparently it's a server timeout, which is odd because the script still runs but you just don't get a response from it. I can't over-ride their settings, I've tried setting max exucution time to no avail, but at least I know what it is now so I've done a workaround for the problem where the script is called for shorter periods of time. Thanks for your help though Psycho and mac_gyver!
  3. I tried changing the success function and it just does nothing instead and doesn't receive the second response. The problem still occurs when I tested it on my friend's laptop. Interestingly though, I tried deleting wordpress and now the script functions differently and throws an error when I run the test. Before the script would startup mid processing and then log "misfire" to the log as in post 15 etc... now that I've uninstalled wordpress, the script no longer logs the misfire but instead I get the following error returned to the client around the same time that it used to send the GET request (I'm using the restful client): Status 500 Internal Server Error Loading time: 45612 Request headers User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo Content-Type: application/x-www-form-urlencoded Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: en-GB,en-US;q=0.8,en;q=0.6 Response headers Date: Tue, 10 Jun 2014 10:54:36 GMT Server: Apache Connection: close Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head..> <title>500 Internal Server Error</title> </head><body> <h1>Internal Server Error</h1> <p>The server encountered an internal error or misconfiguration and was unable to complete your request.</p> <p>Please contact the server administrator, webmaster@kingstonmarketing.localpowermarketing.co.uk and inform them of the time the error occurred, and anything you might have done that may have caused the error.</p> <p>More information about this error may be available in the server error log.</p> <p>Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.</p> </body></html>
  4. Ok, so I'm trying to rack my head around how I can change my AJAX as in post 11 to make it so it will still receive the response from the POST data after receiving the GET response. I'm not sure how could this be done, do you know how I could do it?
  5. By receiving the response from the GET request it seems to close the AJAX connection so it doesn't receive the response from the POST request. Yeah I suppose I'll have to figure out how to fix that.
  6. That was pretty much one of the first things I tried, the script already dies when post data is blank. Pretty much the same thing, no? The problem is not so much the script running but that a response is sent to the client from the stray request (whether that be my javascript client or the restful client). I'm not really concerned about other people running it as long as I don't get a response on my client from their request.
  7. Thanks, the URL of the javascript client is different than the php script which the AJAX calls (I think that's what you're asking). But I must stress that I'm using the Chrome Restful Client to debug what's going on to eliminate any javascript being the issue. The problem happens the same using either my client or the Restful Client. To try and fix the issue, I recently tried to change the .htaccess file to not allow any GET requests in the directory that the php script is in. It works in that it won't run the script for the GET request, but the Restful Client still gets a response. In this case the response is the entire HTML of the frontpage of my wordpress website which I guess has something to do with wordpress' error handling or something... but the problem is that it still gets a response. It's weird that it seems the restful client is even sending GET requests though right? Otherwise it shouldn't receive any responses surely. This is the javascript though if it's still relevant: function SendPHP(str, callback){ str = "q=" + encodeURIComponent(str); $.ajax({ type: "POST", url: "test/errortest.php", data: str, contentType: "application/x-www-form-urlencoded", success: function(msg) { callback(msg); }, error: function(err) { alert(err.toString()); if (err.status == 200) { callback(err); } else { alert('Error:' + err.responseText + ' Status: ' + err.status); } } }); }
  8. I logged the contents of the GET request which ends up being just an empty array. The main PHP script receives parsed POST data from my javascript application, processes it and then when it's finished the AJAX sends the next packet... and so on. But these stray GET requests interrupt the AJAX which receives a blank response in the middle of the processing instead of the response from the POST request when it's finished and so it doesn't send the next packet and doesn't know when the previoius packet is finished processing because of the interruption. The strange thing is that this was all working on a different server as I made the application for a friend. But when I copied it to my server so I could use the app myself I get these GET requests so it doesn't work. I just had a look at your post 6, and I'm still not sure how to ignore GET requests? In my code I make the script die if the data sent to it is blank, but that's not working. Sorry I'm a bit of a newb, how would I make it so the script completely ignores GET requests?
  9. By the way, I've logged the $_SERVER['REQUEST_METHOD'] and the second request is always GET, you're right.
  10. OK thanks, I'll have to look into this. I'm pretty sure it is something the server is doing because I was hosting my original script on a different host and I wasn't having the exact same issue. Also the problem happens in different browser including a restful client. What could the server possibly be doing, (just so I have a vague idea if what to look for)? Thanks (Note I use shared hosting)
  11. Ok, I'm logging the user agent with: $agent = $_SERVER['HTTP_USER_AGENT']; And I got this on a test run (error after 12th entry): IP Logged: 86.31.**.99 --- 05/06/2014 19:56:22User agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 --- 05/06/2014 19:56:22Post data: foobar --- 05/06/2014 19:56:22*** Error check started *** --- 05/06/2014 19:56:221 --- 05/06/2014 19:56:222 --- 05/06/2014 19:56:393 --- 05/06/2014 19:56:544 --- 05/06/2014 19:57:125 --- 05/06/2014 19:57:196 --- 05/06/2014 19:57:327 --- 05/06/2014 19:57:448 --- 05/06/2014 19:57:569 --- 05/06/2014 19:57:5910 --- 05/06/2014 19:58:0211 --- 05/06/2014 19:58:1312 --- 05/06/2014 19:58:26IP Logged: 86.31.**.99 --- 05/06/2014 19:58:38User agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 --- 05/06/2014 19:58:38Post data: --- 05/06/2014 19:58:38MISFIRE!!! --- 05/06/2014 19:58:3813 --- 05/06/2014 19:58:4014 --- 05/06/2014 19:58:5515 --- 05/06/2014 19:59:04
  12. Ok I've just tested with the IP logged and post data, and it shows it's coming from my IP: IP Logged: 86.31.**.99 --- 05/06/2014 19:42:46Post data: foobar --- 05/06/2014 19:42:46*** Error check started *** --- 05/06/2014 19:42:461 --- 05/06/2014 19:42:462 --- 05/06/2014 19:42:553 --- 05/06/2014 19:43:014 --- 05/06/2014 19:43:115 --- 05/06/2014 19:43:256 --- 05/06/2014 19:43:337 --- 05/06/2014 19:43:518 --- 05/06/2014 19:44:099 --- 05/06/2014 19:44:1310 --- 05/06/2014 19:44:2311 --- 05/06/2014 19:44:4212 --- 05/06/2014 19:44:49IP Logged: 86.31.**.99 --- 05/06/2014 19:45:02Post data: --- 05/06/2014 19:45:02MISFIRE!!! --- 05/06/2014 19:45:0213 --- 05/06/2014 19:45:0714 --- 05/06/2014 19:45:2415 --- 05/06/2014 19:45:3916 --- 05/06/2014 19:45:55Updated script:[code]<?php$q = $_POST['q'];$ip = $_SERVER['REMOTE_ADDR'];writelog("IP Logged: ".$ip);writelog("Post data: " . $q);if ($q==""){ writelog ("MISFIRE!!!"); die;}writelog("\n*** Error check started ***");for ($i = 1; $i <= 50; $i++) { writelog ($i); sleep(rand(2,20));} function writelog($towrite){ $tdate=date('d/m/Y H:i:s'); $file = 'log/testlog.txt'; $current = $towrite." --- ".$tdate."\n"; file_put_contents($file, $current, FILE_APPEND);}writelog("*** Error check ended ***");?>[/code]
  13. I've managed to isolate a problem I'm having with my php script. It would seem the script randomly restarts itself with blank post data while it's running. I've managed to mimick the problem using a very basic php script which just pauses and writes to a log: <?php $q = $_POST['q']; if ($q==""){ writelog ("MISFIRE!!!"); die; } writelog("\n*** Error check started ***"); for ($i = 1; $i <= 50; $i++) { writelog ($i); sleep(rand(2,20)); } function writelog($towrite) { $tdate=date('d/m/Y H:i:s'); $file = 'log/testlog.txt'; $current = $towrite." --- ".$tdate."\n"; file_put_contents($file, $current, FILE_APPEND); } writelog("*** Error check ended ***"); ?> To rule out any problems with my AJAX htmlhttp requests, I simply send the script some irrelevant post data using Chrome's Advanced Restful client. This is the ouput of the log from an example test run: *** Error check started *** --- 05/06/2014 18:27:30 1 --- 05/06/2014 18:27:30 2 --- 05/06/2014 18:27:44 3 --- 05/06/2014 18:27:49 4 --- 05/06/2014 18:27:59 5 --- 05/06/2014 18:28:04 6 --- 05/06/2014 18:28:22 7 --- 05/06/2014 18:28:33 8 --- 05/06/2014 18:28:39 9 --- 05/06/2014 18:28:52 10 --- 05/06/2014 18:29:08 11 --- 05/06/2014 18:29:22 12 --- 05/06/2014 18:29:30 13 --- 05/06/2014 18:29:43 MISFIRE!!! --- 05/06/2014 18:29:46 14 --- 05/06/2014 18:29:56 15 --- 05/06/2014 18:30:07 16 --- 05/06/2014 18:30:09 17 --- 05/06/2014 18:30:15 18 --- 05/06/2014 18:30:32 19 --- 05/06/2014 18:30:52 20 --- 05/06/2014 18:30:54 Note the logged "Misfire" after the 13th entry. This shows the script tried to run again with blank post data, the same problem I'm having in my more complex script. Why could this be happening? It's not anyone else calling the script, nobody knows about the site and I've ruled it out by logging the IP in my real script.
  14. The email subject and body are written by the user into a text field on the javascript application. That's sent with the packets as in: http://forums.phpfreaks.com/topic/287756-php-script-restarts-randomly-with-same-post-data/?p=1476195
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.