aidangig Posted September 18, 2017 Share Posted September 18, 2017 Take a look at my code. The code keeps executing and writing to the links.xml. The issue is such a headache. I can't figure why it won't stop... <?php$xml = simplexml_load_file('/home/thecookie12/public_html/links.xml');$entry = $xml->addChild('link');$entry->addChild('title', chop('Boston Area - ' . $_GET['title'], '.html'));$entry->addChild('url', 'http://boston.lit.life' . '/' . $dir_auth1 . '/' .str_replace(" ", "-", $randHTML));$xml->asXML('/home/thecookie12/public_html/links.xml')?> This piece of code keeps writing the $entry variables values into the links.xml file. The $entry variables are the nodes to add into the xml file. I'm trying to find the source of the issue as why the code appears to loop in functionality... My xml file looks like this after the page loads with this code in it. http://lit.life/links.xml The code above keeps writing into the links.xml file for a few seconds or as the pages loads. I want only 1 entry with added to the .xml file. Please open the link to see the entire script. Definitely where the problem is http://lit.life/code.txt Quote Link to comment Share on other sites More sharing options...
requinix Posted September 18, 2017 Share Posted September 18, 2017 I don't see any loops in there so I guess the answer to why it keeps executing is because you keep loading the page. So... stop loading the page? Exactly how is the system supposed to behave and what is it that makes you think there is a loop? Quote Link to comment Share on other sites More sharing options...
aidangig Posted September 18, 2017 Author Share Posted September 18, 2017 I don't see any loops in there so I guess the answer to why it keeps executing is because you keep loading the page. So... stop loading the page? Exactly how is the system supposed to behave and what is it that makes you think there is a loop? Okay so what is the best way to stop loading the page so that the code doesn't keep running? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 18, 2017 Share Posted September 18, 2017 So now the question is : How are you loading the page? Or maybe: What is loading the page? Quote Link to comment Share on other sites More sharing options...
aidangig Posted September 18, 2017 Author Share Posted September 18, 2017 So now the question is : How are you loading the page? Or maybe: What is loading the page? So like what elements? The Facebook comments plugin makes the site load much longer. There are a few other 3rd party website javacript lines of code, but other than that everything is from me. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 18, 2017 Share Posted September 18, 2017 Huh? What are you talking about now? Elements? Facebook? Javascript? Quote Link to comment Share on other sites More sharing options...
requinix Posted September 18, 2017 Share Posted September 18, 2017 (sigh) You say it keeps executing that code. There is no loop in the rest of the file so the entire file must be executing more than once, right? So the question is how the file is loading. With basic sites the file you put into the address bar of your browser is the one that gets executed, and it doesn't get executed more than once*. So if the file is running more than once and the browser is not doing it, what is? * I've seen instances of poor Javascript practices causing a -linked page to run twice Quote Link to comment Share on other sites More sharing options...
aidangig Posted September 18, 2017 Author Share Posted September 18, 2017 I know that is why I am soooo confused it is really annoying. Logically this makes no sense! Why is the code continuously running... Is that the only reason why this is happening? How the page loads? Nothing is wrong with the actual code itself? Please let me know. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 18, 2017 Share Posted September 18, 2017 I'll ask the same question AGAIN. How is the script being started/run/executed/initiated? That's what we want to know. And just to be sure : Is the script ACTUALLY only 6 lines long? There is NO MORE? And - what is the name of this script? Quote Link to comment Share on other sites More sharing options...
requinix Posted September 18, 2017 Share Posted September 18, 2017 I know that is why I am soooo confused it is really annoying. Logically this makes no sense! Why is the code continuously running... Is that the only reason why this is happening? How the page loads? Nothing is wrong with the actual code itself? Please let me know. We are not sitting at your computer. We can't see what you're doing. We can't see your site. We are useless unless you can answer our questions. Quote Link to comment Share on other sites More sharing options...
aidangig Posted September 18, 2017 Author Share Posted September 18, 2017 I'll ask the same question AGAIN. How is the script being started/run/executed/initiated? That's what we want to know. And just to be sure : Is the script ACTUALLY only 6 lines long? There is NO MORE? And - what is the name of this script? How do I tell how the script is being executed? Any resources you can share? My entire is script source is here What happens is a user makes a post and a new post.php file is duplicated with the user input from the previous page. The php simplexml code above is being duplicated constantly (multiple by the second) into the links.xml file. The post.php page An actual page post page is here - http://boston.lit.life/aidangig59/Mass-Effect-Andromeda-.html Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 18, 2017 Share Posted September 18, 2017 OK - You didn't answer a single one of my questions. You said this is "your" code. Yet you don't know how you are running it? How can you say that "you don't know how to run it"??? I quit. You're just wasting our time if you can't tell us how you are executing your own script. I'd wish you good luck but you need more than luck Quote Link to comment Share on other sites More sharing options...
requinix Posted September 19, 2017 Share Posted September 19, 2017 How do I tell how the script is being executed? Any resources you can share?For one, you need to know how your application works. Are individual PHP files executed directly? Do you have a front controller? Using MVC? We don't konw. And if you don't know then you need to. Let's try something really simple. file_put_contents("/tmp/asdf", json_encode($_SERVER, JSON_PRETTY_PRINT) . "\n", FILE_APPEND);Put that in your code where the links.xml thing is happening, run the page once, then look at the /tmp/asdf file. What do you see? Quote Link to comment Share on other sites More sharing options...
aidangig Posted September 21, 2017 Author Share Posted September 21, 2017 For one, you need to know how your application works. Are individual PHP files executed directly? Do you have a front controller? Using MVC? We don't konw. And if you don't know then you need to. Let's try something really simple. file_put_contents("/tmp/asdf", json_encode($_SERVER, JSON_PRETTY_PRINT) . "\n", FILE_APPEND);Put that in your code where the links.xml thing is happening, run the page once, then look at the /tmp/asdf file. What do you see? I definitely think the code is executed directly, almost positive. As soon as the page starts loading on even a page refresh it will duplicate the content in the links.xml file... I don't have an MVC or front controller. Quote Link to comment Share on other sites More sharing options...
aidangig Posted September 21, 2017 Author Share Posted September 21, 2017 So I might have figured it out myself. Is there anyway I can mark it as solved for now? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.