PHP - Multiple Http Requests?
I was just wondering if when I write a new function that uses AJAX should I use the same http request for my whole website or should I make seperate ones for each function? Also if you use the same one do you need to do anything to it once it has been used to set the ready status back to 0?
Thanks Similar TutorialsHello! I'm trying to understand exactly how http requests relate to a php script. 1) What would be considered a large amount? 2) How can I see how many I have for a given page? Thank you, Eric I have an object which is very expensive to create, and is fairly large but by no means enormous. The object has two tasks: Display to the user what can be changed in a database. Make some or all of those changes based on user input.Instead of creating it first to perform the first task, I would like to serialize it and store it somewhere and then restore it to perform the second task to reduce user wait time. Communication of both tasks is as follows where the web client first makes a XMLHttpRequest and then cURL is used for the remaining: Web Client -> Web Server -> REST API Server -> Time Historian Application (and then back in the same order) In addition, both of these tasks take significantly longer than 30 seconds resulting in cURL error 28. I certainly can investigate to determine which of the requests are causing this error, however, feel that the solution to persisting the object might solve this issue as well. I am thinking of making the REST API server responsible for temporarily storing the object, and am considering the following: Web client makes XMLHttpRequest to web server and passes session cookie. Web server makes cURL request to REST API server and passes that same cookie (maybe a bad idea?). REST API server initiates the time historian application, spawns some new process, and replies to the web server maybe with some expected wait time duration, and web server in turn responds to web client. Spanned process when object is complete serializes the object's content and saves it as JSON using the session cookie as the filename. Web client periodically makes requests to web server which in turn make requests to REST API server and when the JSON file is available, recreates the object, executes the applicable method, and replies with the applicable content. Web client sends user data to the web server and in turn to the REST server to initiate the second task. Web client similarly periodically makes requests to web server which in turn make requests to REST API server to check if complete and if so the JSON object file is deleted. If request has not been fulfilled within 24 hours or so, JSON object file is deleted.I would appreciate any general feedback or recommendations how best to accomplish this, and whether using some 3rd party framework such as Gearman, ReactPHP, redis, etc might simplify matters. Thank you Trying to run a simple program that, when submitted, stores the username and password as cookies. When clicking Submit, I get the error "HTTP Error 405 - The HTTP verb used to access this page is not allowed". If the username and password fields are left blank when submitting it's suppose to give a message to enter a username and password, but, I still get that error message. HTML form: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Week 1 Project--Cookies</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <form action="cookie1.php" method="post"> <h2 align="center">Cookies</h2> <br /> <div> <p>Enter your username and password and click "Submit":</p><br /> <p>Username:<input type="text" name="username" size="20"></p> <p>Password:<input type="text" name="password" size="20"></p> </div> <br /> <div><input type="submit" name="submit" value="Submit" /></div> <br /> <div> <input type="reset" name="Reset" value="Start Over" /> </div> </form> </body> </html> PHP file: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Cookie File</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <div> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { setcookie('username', $_POST['username'], time() + 2592000); setcookie('password', $_POST['password'], time() + 2592000); } if(($_POST['username'] == "") || ($_POST['password'] == "")) { print "You must enter both a username and password. Press the Back button on your browser and try again."; } else if (isset($_COOKIE['username'])) { print "Welcome, " .$_COOKIE['username']; } ?> </div> </body> </html> I think it's fsockopen that enables you to do web requests right?? I was wondering if you could also make it use a proxy instead of your website's IP. Would that be possible? How can I track session requests, so I can, after a certain number of requests (let's say ten because it's physcologically pleasing), have the id regenerated? Hello there everyone. I'll try to explain as thorough as I can so please bare with me a bit. One you want to surf the web through a proxy in firefox, you go to tools > options > network > settings and enter proxy details which for example are like this. 173.123.123.4 and port 8080. I want to do pretty much the same thing with php for my visitors. I have www.site1.com which will have all my scripts and stuff. I want it to somehow redirect or load to www.site2.com USING A PROXY so that when the visitor reach site2, it's as if they have edited their firefox settings to view site2 using a proxy. That way visitors will always be anonymous on www.site2.com. While searching, I found this: http://stackoverflow.com/questions/3889715/php-requests-through-proxy Which seems simple enough but does not work unfortunately. Not that I'm even sure that it's indeed what I want to do but it seems like it...lol. Thanks a lot for any help provided. Hi, I am trying to make a web interface for a robot, I have written php to send/recieve values via a serial port to my robot. They work. I am now tring to develop my web interface. I'm using java to generate http requests client side in the form of; Code: [Select] /request?command=Forward¶m1=254 I was wondering how I can parse the command and param1 in php sereverside? Or is there a better alternative? I created an app for my website, set action (read) and object (article), and placed the objects code (META tags in the head) at the article page on my website. Now, I want to know how to send a cUrl request whenever a user reads an article on my website, so it'll feature on his wall. When I press the "get code" link near the action, that's what I get: Code: [Select] curl -F 'access_token=***' \ -F 'article=http://example.com' \ 'https://graph.facebook.com/me/yellowheart:read' (There's an actual access token of course). Now, how do I make it happen? Daniel Purpose: Building a search function for a site, that's supposed to be fast, give results as a user types. Queries would be something like: "brand1 brand2 brand3" . My idea is , instead of querying the database on each ajax request. A keyed array is created once. Like: ['brand1' => id , 'brand2 => id2 ]. This array is stored in memory. The next time a query is sent, the array which is instantly available in memory, and can be simply queried $storedArray['brand1']to fetch any existing ids instantly. The array size would be about 750 Kb. 60000 rows. I don't have much experience with caching , so looking for advise whether what I am trying to do even makes any sense or necessary. I know there are solutions like memcache. But not sure if my tiny project requires them. Also does opcache help here ? Would serializing the array be too slow ? Please ask if any questions. Thanks I have script on my web hosts server built into pages that will be offered to the public, eg: index.php will have some script amongst the html, this script calls other webpages on the net eg: wiki.org Now my question is, when that script runs when somebody accesses that page, will the website eg: wiki.org record the users browser info and ip who called my index page or will it record the webhosts server details as the one making the requests? Hi all, Something i forget to ask all the time, but now i don't. While reading again about image sprites, it tells that it's nice because it decreases the amount of http requests. Now I thought what about all those requires and includes of php aren't they doing the same thing? Not to mention OOP which would not exist without the 2(4). Does anyone know if this indeed increases the amount of http requests. And if so, if there is a certain good practise to lower the amount, by just combining functions in 1 file. I would love to hear from some guru's How do I only redirect the page when index.php is present? It's been a while since I've needed to whip anything substantial up from scratch, so my scripting is a little (lot) fast and loose (weird/inefficient) here. I'm trying to mock up a script that's essentially a quiz/survey. There are a handful of topics, each with a few screens of yes/no questions. At the end, it returns a list of recommendations based on the answers gathered. The script is posting back to itself. Using print_r ($_SESSION), it seems like all of the post values for the first screen of questions are being assigned to the session array as expected. When the second screen of questions is answered, their values are assigned as well, but the values for the first set go away completely. This continues through subsequent screens, with the values from the previous screen present and all others before missing. I'd really appreciate a look at my code to see if you tell me the cause or error(s). Thanks! <?php session_start; include('_config.php'); // database connect $dbc = mysqli_connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname); // set to section 1, page 1 if no values are in _POST array if (($_SERVER['REQUEST_METHOD'] == 'GET') || (!isset($_POST['section']))) { $section = 1; $page = 1; } else { // something was posted, so...set those values in session variable foreach($_POST as $key => $data) { $_SESSION[$key] = $data; } // debug: display contents of the session array print_r ($_SESSION); // which section and page? $section = (int) $_POST['section']; $page = (int) $_POST['next']; } // check if last topic $query = "SELECT * FROM hw_topics"; $data = mysqli_query($dbc, $query); if ($section == mysqli_num_rows($data)) { $last_section = true; } else { $last_section = false; } // get current topic name and info $query = "SELECT topic, display_name, pages_in_topic FROM hw_topics WHERE topic_id = '$section'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $row = mysqli_fetch_array($data); $topic_display_name = $row['display_name']; $pages_in_topic = $row['pages_in_topic']; } // test if last page in topic $topic_pages = $row['pages_in_topic']; if ($page == $topic_pages) { $last_page_in_section = true; } else { $last_page_in_section = false; } // set form action (set to this script or to recommendations when last section is complete if (($last_section == true) && ($last_page_in_section == true)) { $form_action = $CFG->reccomend; } else { $form_action = $_SERVER['PHP_SELF']; } // get current page headline $query = "SELECT page_headline FROM hw_pages WHERE topic_id = '$section' AND page_number = '$page'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The headline row was found so display the headline $row = mysqli_fetch_array($data); $page_headline = '<h2>' . $row['page_headline'] . '</h2>'; } // Grab the question data from the database to generate the list and form fields $query = "SELECT question_id, question_number, question_text FROM hw_questions WHERE topic_id = '$section' AND page_id = '$page' ORDER BY question_number"; $data = mysqli_query($dbc, $query); $questions = array(); while ($row = mysqli_fetch_array($data)) { array_push($questions, $row); } include($CFG->includesdir.'/header.php'); ?> <div id="head"> <h1>Assessment<?php if (isset($topic_display_name)) { echo ': <em>' . $topic_display_name . '</em>'; } ?></h1> <p class="paging">Page <?php echo $page; ?> of <?php echo $pages_in_topic; ?></p> </div><!-- #head --> <div id="content"> <p class="instr">Please complete this survey. We'll generate a list of recommendations and resources for your organization.</p> <div id="questions"> <?php echo $page_headline; ?> <form method="post" action="<?php echo $form_action; ?>"> <table border="0" cellpadding="0" cellspacing="0"> <thead> <tr> <td></td> <td class="qtext"></td> <td class="qanswer">yes</td> <td class="qanswer">no</td> <td class="pad"></td> </tr> </thead> <?php if ($questions) { // display question rows foreach ($questions as $question) { echo '<tr>'; echo '<td class="qnumber">' . $question['question_number'] . '.</td>'; echo '<td class="qtext"><p>...' . $question['question_text'] . '</p></td>'; echo '<td class="qanswer"><div class="radio" id="box-yes"><input type="radio" value="yes" name="qid_' . $question['question_id'] . '" id="qid_' . $question['question_id'] . '" class="radio" /></div></td>'; echo '<td class="qanswer"><div class="radio" id="box-no"><input type="radio" value="no" name="qid_' . $question['question_id'] . '" id="qid_' . $question['question_id'] . '" class="radio"'; $field_name = 'qid_' . $question['question_id']; if (isset($_SESSION[$field_name])) { echo ' checked="checked"'; } echo ' /></div></td>'; echo '<td class="pad"></td>'; echo '</tr>'; } } else { echo '<tr>'; echo '<td colspan="3" class="qtext"><p>No questions found in the database for this page.</p></td>'; echo '<td class="pad"></td>'; echo '</tr>'; } ?> </table> <ul id="controls"> <?php if ($last_page_in_section == true) { $section++; $page = 1; } else { $page++; } echo '<input type="hidden" value="' . $section . '" name="section" />'; echo '<input type="hidden" value="' . ($page) . '" name="next" />'; if (($last_section == true) && ($last_page_in_section == true)) { echo '<li><input type="submit" value="Submit Answers and Get Recommendations" name="submit" id="submit" /></li>'; } else { echo '<li><input type="submit" value="Next Page" name="submit" id="next" /></li>'; } ?> </ul><!-- #controls --> </form> </div><!-- #questions --> <?php mysqli_close($dbc); include($CFG->includesdir.'/footer.php'); ?> I am trying to build an app which will scan a site multple times, the only problem is the 403 error, how do I get around this. Searching seems to imply curl or user_agent, but can't get it working. Any suggestions? Thanks Not sure if this is possible. What I am trying to do is remove a section of text a user posts. ie: go to this url: http://url.com or http://this.domain.org I already have it to strip they <a href="whatever but not sure if I can do the other. Any help would be appreciated. Thanks Hi, I don't know very much about php. I don't know any at all, actually. I play a game called Roblox where you get to use the programming languange, "Lua" to script your own games. What I am requesting has been done before on this game, but I only know Lua. I was also told PHP cURL is needed. Anyways, let me get to the point. I am essentially trying to create a system on my webserver (You can send HTTP Requests to external sites in this game via script) that will essentially log into an account on Roblox, to perform a task. My current idea would be to have the Lua script send a request to my webserver with an generated code that would access the username and password of my roblox account (Which would be on the webserver). It would then perform a task. Is this a good way to go about this? If not, I am open to suggestions. If you can find the time to actually help me set this up on my webserver, I would greatly appreciate it! I'm also sorry if this is the wrong place for this post, I'm new here. Hi All, I know it is a silly error but I am very new to PHP (only 2 days!!!) & unable to resolve this. I have seen a lot of resolutions online for example: 1) Copying the "php5isapi.dll" file to the PHP directory & under "Program Files" as well. 2) Copying the "favicon.ico" file etc etc Before I could elaborate the issue, please note that I am a Windows user - Windows XP (I know its not the best of the OS's to work with!!!) When initially I started getting the issue, I checked the "error.log" file under "C:\Program Files\Apache Software Foundation\Apache2.2\logs" & following is what I saw: ----------------------- [Sun Sep 18 14:13:25 2011] [notice] Server built: Sep 9 2011 10:26:10 [Sun Sep 18 14:13:25 2011] [notice] Parent: Created child process 4420 [Sun Sep 18 14:13:25 2011] [notice] Child 4420: Child process is running [Sun Sep 18 14:13:25 2011] [notice] Child 4420: Acquired the start mutex. [Sun Sep 18 14:13:25 2011] [notice] Child 4420: Starting 64 worker threads. [Sun Sep 18 14:13:25 2011] [notice] Child 4420: Starting thread to listen on port 80. [Sun Sep 18 14:14:55 2011] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.ico [Sun Sep 18 14:21:37 2011] [notice] Server built: Sep 9 2011 10:26:10 [Sun Sep 18 14:21:37 2011] [notice] Parent: Created child process 7976 [Sun Sep 18 14:21:37 2011] [notice] Child 7976: Child process is running [Sun Sep 18 14:21:38 2011] [notice] Child 7976: Acquired the start mutex. [Sun Sep 18 14:21:38 2011] [notice] Child 4420: Released the start mutex [Sun Sep 18 14:21:38 2011] [notice] Child 7976: Starting 64 worker threads. [Sun Sep 18 14:21:39 2011] [notice] Child 4420: All worker threads have exited. [Sun Sep 18 14:21:39 2011] [notice] Child 4420: Child process is exiting [Sun Sep 18 14:21:39 2011] [notice] Child 7976: Starting thread to listen on port 80. [Sun Sep 18 14:21:52 2011] [error] [client 127.0.0.1] File does not exist: C:/Rahul/Personal/Web Development/favicon.ico ---------------------- Then I created an icon file and named it "favicon.ico" & placed it in the following destinations: 1) C:/Rahul/Personal/Web Development/ and 2) C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/ but to no avail But interestingly & surprisingly, the error.log file stopped giving any of the above error messages but I still get the HTTP Error. Following is the error message that I get on the browser: -------------------------- Server error The website encountered an error while retrieving http://localhost/Forms/insert%20data.php. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this webpage later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. -------------------------- Now, just to let you know which php I am using, so, just to let you know, I just copied the html & php from http://www.w3schools.com/PHP/php_mysql_insert.asp. Following are they: HTML: ---------------------------- <html> <body> <form action="insert data.php" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> ----------------------------- PHP ----------------------------- <?php $con = mysql_connect("localhost","root","orange"); if (!$con) { die('Could not connect: ' . mysql_error()); } echo "Connection established"; mysql_select_db("my_db", $con); $sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES ('$_POST['firstname']','$_POST['lastname']','$_POST['age']')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added with name: " $_POST[firstname] $_POST[lastname]; mysql_close($con) ?> ------------------------- I hope someone is able to help me in this & I guess I have mentioned everything I could to explain the error! Many thanks in advance! Rahul i have been searching for a solution for about a day already. can anyone help me on how to use the http functions (if thats what it is called) in php? http://www.php.net/manual/en/book.http.php like for example. i need to use the http_get() function but it returns Fatal error: Call to undefined function.. in the manual it says that i need to put php_http.dll on the ext dir and enable it in php ini like this.. extension=php_http.dll ..which i already did im working under.. windows xp sp3 php 5.3.1 thanks guys I am learning PHP using the book "Beginning PHP and MySQL 5 - From Novice to Professional", and I have come across a lesson in the book which I am stuck on. The lesson is on using the echo() statement. I've typed in the following code and saved it as a php file.... <?php $heavyweight = "Lennox Lewis"; $lightweight = "Floyd Mayweather"; echo &heavyweight, " and ", $lightweight, " are great fighters."; ?> My Apache and PHP is working fine as my other PHP files work properly. When I try and view the file it says... "The website encountered an error while retrieving http://localhost:8888/phpdocs/multiplestringsecho.php. It may be down for maintenance or configured incorrectly." and when I click on more information it says... "HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request." Any ideas? Have I done something wrong? Any help would be much appreciated. when i upload this code and refresh the page nothing shows up the only thing htat shows up is HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. please helop Code: [Select] <?php $title = "Home"; ?> <?php require("styles/top.php"); ?> <?php if ($username){ echo "<table> </div></td> </tr> <tr> <td width="244" valign="top"><br /> <form id="form1" name="form1" method="post" action="search_results.php" style="margin-left:20px;"> <input name="var" type="text" class="size12" id="var" style="width:124px; background-color: #A4D1FF;" /> <input name="button" type="submit" class="size11" id="button" value="Search" /> </form> <br /> <div id="leftNav" style="margin-left:22px;"> <!-- Start tv --> <strong><font color="#FFFFFF"><span class="size16">TV</span></font></strong><br /> <a href="tv.php?c=tv&sc=cartoons">Cartoons <font size="-3" color="#FFFFFF"></font></a><br /><a href="tv.php?c=tv&sc=news">News <font size="-3" color="#FFFFFF"></font></a><br /><a href="tv.php?c=tv&sc=adventures">Adventures <font size="-3" color="#FFFFFF"></font></a><br /><a href="tv.php?c=tv&sc=horror">Horror<font size="-3" color="#FFFFFF"></font></a><br /><a href="tv.php?c=tv&sc=Drama">Drama<font size="-3" color="#FFFFFF"></font></a><br><br /> //End TV --> // Start Videos --> <strong><font color="#FFFFFF"><span class="size16">Videos</span></font></strong><br /> <a href="videos.php?c=videoss&sc=children">Children <font size="-3" color="#FFFFFF"></font></a><br /><a href="videos.php?c=videos&sc=music">Music<font size="-3" color="#FFFFFF"></font></a><br /><a href="videos.php?c=videos&sc=comedy">Comedy<font size="-3" color="#FFFFFF"></font></a><br /><a href="videos.php?c=videos&sc=youtubemovies">Youtube Movies <font size="-3" color="#FFFFFF"></font></a><br /><a href="videos.php?c=videos&sc=sports">Sports <font size="-3" color="#FFFFFF"></font></a><br /> <br> <!-- End videos--> <!-- Start Movies --> <strong><font color="#FFFFFF"><span class="size16">Movies</span></font></strong><br /> <a href="movies.php?c=movies&sc=comedy">Comedy <font size="-3" color="#FFFFFF"></font></a><br /> <a href="movies.php?c=movies&sc=action">Action <font size="-3" color="#FFFFFF"></font></a><br /><a href="movies.php?c=movies&sc=adventure">Adventures <font size="-3" color="#FFFFFF"></font></a> <a href="movies.php?c=movies&sc=horror">horror <font size="-3" color="#FFFFFF"></font></a><br /> <a href="movies.php?c=movies&sc=drama">Drama<font size="-3" color="#FFFFFF"></font></a><br /><br /> <br /> //End Movies </div> </table>"; } else echo "<h2><font color='red'>You must be logged view this Part.</font></h2>"; ?> <?php require("styles/bottom.php"); ?> |