iamkoby Posted October 28, 2008 Share Posted October 28, 2008 Hi ! I'm looking for hours for a way to call a script with a variable (it can be either GET or POST) but without waiting for the script to reply. This script takes at least 7 seconds to respond so if i'm using file_get_contents I'm left with a suspend of 7+ seconds in my script. I have NO interest in the response of that script since it returns nothing so how can I just call it, leaving it to work and continue in my own script ? Your help is greatly appreciated. Thank you! Link to comment https://forums.phpfreaks.com/topic/130433-posting-a-variable-to-a-script-without-waiting-for-an-answer/ Share on other sites More sharing options...
bobbinsbro Posted October 28, 2008 Share Posted October 28, 2008 do you want to make the call from another php file or from the client-side? Link to comment https://forums.phpfreaks.com/topic/130433-posting-a-variable-to-a-script-without-waiting-for-an-answer/#findComment-676638 Share on other sites More sharing options...
iamkoby Posted October 28, 2008 Author Share Posted October 28, 2008 From another php file. This is the flow: User submits a form on the client side. The php file (let's call it PHP1) receives the form and calls another script (PHP2). PHP2 builds a customized page for the submitted information and saves it in the database. This process takes 7+ seconds and returns nothing to PHP1. PHP1 wait for PHP2 to finish (although PHP2 doesn't return anything) and that delays the user response too much. I need PHP1 to get the form, send it (only two variables) to PHP2 and respond to the user: "Your details sent for compilation. You'll get a mail with a link when your page is ready.". Link to comment https://forums.phpfreaks.com/topic/130433-posting-a-variable-to-a-script-without-waiting-for-an-answer/#findComment-676650 Share on other sites More sharing options...
bobbinsbro Posted October 28, 2008 Share Posted October 28, 2008 i think i would consider using AJAX for that. look up xmlhttprequest() in google. there are tons of tutorials laying around for this. otherwise, i think that the windows version of php has an extension for working with multiple threads, but i know nothing about using it, and it's probably a much more difficult solution than the ajax. Link to comment https://forums.phpfreaks.com/topic/130433-posting-a-variable-to-a-script-without-waiting-for-an-answer/#findComment-676692 Share on other sites More sharing options...
iamkoby Posted October 29, 2008 Author Share Posted October 29, 2008 I don't think you understood my question - AJAX is in the client side. I'm looking for asynchronous php requests made on the server - from one script to another. Link to comment https://forums.phpfreaks.com/topic/130433-posting-a-variable-to-a-script-without-waiting-for-an-answer/#findComment-677218 Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 right. sorry. here's what i found: if you're web server is running on a *nix system (only *nix), php has a function called pcntl_fork() (look it up in the maual) for forking php processes to the background. it looks like this functionality is not compiled into php by default and you have to use a --enable-pcntl flag at compile. what the function basically does, is copy the state of your current script to a new child process, and the child continues running from the line immediately after the function call. to make the child process run 1 thing and the parent another, you can do something like: $pnID = pcntl_fork(); if ($pnID){ //since child only starts running from here, it wont have $pID initialized //parent code } else{ //child code } i found a few tutorials that go into more detail: http://www.electrictoolbox.com/article/php/process-forking/ http://immike.net/blog/2007/04/08/fork-php-and-speed-up-your-scripts/ http://www.welldonesoft.com/technology/articles/php/forking/ they're all more or less the same. * note: one of the above tutorials recommends not to use this function for web server scripts, (maybe for security reasons?). hope this is what you were looking for. Link to comment https://forums.phpfreaks.com/topic/130433-posting-a-variable-to-a-script-without-waiting-for-an-answer/#findComment-677235 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.