PHP - Alternative Queue System
Hi folks, I'm trying do a system like a queue, but doesn't work like i expected. OS: Windows (IIS) PHP: 5.2 So, let me tell you, what i'm doing. 1º Click in one button and insert the entry into database $stmt = odbc_prepare($conn, 'INSERT INTO queue (ask_date, run_date, executed, user_id) VALUES (GETDATE(), NULL, 0, ?)'); 2º After that i will run a script to check values executed = 0 $handle = new COM('WScript.Shell'); $handle->Run("php generate.php", 0, false); 3º Check values executed = 0 and update de column executed to 1 (generate.php) $sql = "SELECT * FROM queue WHERE executed=0;"; $rsQueue = odbc_exec($conn, $sql); while (odbc_fetch_row($rsQueue )) { //code here } My problem is, when i click in button it will open always new process (php.exe). (2 clicks - 2 processes; 3 clicks - 3 processes; etc..) My ideia is, first button click execute the script (2º) but the other times if script is running, only add the content to queue table to be executed in current process. Someone have any ideia? Thank you! Similar TutorialsHi all I am having a nightmare coming up with something and I wonder if I could pick everyones brain. I am helping to setup a mini web system for a friends dads work, the server is held internally on a very old machine, the current system runs ok and I am just helping to add some new things in. One of the functions they have is a "job" tool, which allows people to submit a small form of data about the job they are currently doing, this is used by internal and external staff. There network is really old and slow as well as the server the scripts are on, and they have no money at the moment to upgrade it, one of the reasons for these enhancements is so they can free up some money, so i'm doing my best to help them. The problem I am having is that when more than 150 users are submitting the form at the same time, the PHP pages are just timing out and the user has to go back to stage 1, their peak has been 230 users, which caused everyone a problem. So I wonder, is there anyway to create a queue style system with a countdown timer? So for example, when the user logs in, if there are more than 60 active users currently submitting on that form, then it would place that user in a queue for X number of seconds\minutes, then when one of those 60 users finish with the form or their 10 minutes is up, the user logged in is then forwarded to the form allowing them to complete it. I was going to give each user a maximum of 10 mins to complete the form before they are chucked out the queue, if that's possible. I was thinking about maybe logging them into a new bigger server online, then when number of user sessions drops below 60 on the current internal server, then they are forward to it, which allows them to complete the form, so you only ever have 60 users on the internal server at once. But I have 0 clue where to start. Is this a totally custom hard job? Or is there something anyone can point me to? Thanks very much all Johnny boy Hi to all the members of this great community, This is my first post here and I am new in PHP and in general web programming, my background is in C and C++ programming languages that's why I want to make some comments with regards to PHP and getting your feedbacks. In C++ one exercise considered that someone knows the basics of the language is to implement a general dynamic queue that is the client programmer can put an arbitrary number of objects into a queue and using templates you can instantiate different queues holding different kind of objects. I have grasped the most important parts of the language and I am pondering if you can effectively implement something like the above using PHP. I have googled this, and I have seen so far just a very simple implementation in PHP. He has defined his queue using an array having a fixed size and he just moved an index up and down through the array while inserting and poping elements from the queue. if you want to implement a dynamic queue the only way it comes to my mind just off the top of my head is to use the the construct [] to add dynamically element at the end of the queue and when you want to pop up an element you just have to unset(your current queue which is an array) create another array (smaller by one element than the previous one) copy the elements at the appropriate positions I just wanted, people with a C++ programming experience to give me some feedback about this topic and to give me some basic idea how could we implement a general queue in PHP. For example could we implement a queue w/o using an array? I would appreciate any comment. Greetings from Greece Hey Guys, I have the following problem. I have a lot of users sending querys to my DB at the same time, and for example each time a user sends the query, a field with a number increases. Sometimes that number increases like this: 10.11, 10.12, 10.13, 10.15, 10.14 When it obviously should be: 10.11, 10.12, 10.13, 10.14, 10.15 Maybe (in this example) the query from 10.15 finished first (got inserted on DB) than the query from 10.14. My question is if there is some kind of function or line of code to have some kind of queue between the Querys...so if a query that is received first must finish and the the next can go ahead and query. Hope I am making myself clear, Looking forward any kind of help and/or suggestions. Thanks a lot in advance! Hi. I am sending out email with a php script - about 5000 at a time by send 15 or so every 20 seconds which works fine. Sometimes I need to add an attachemnt. I then find that the script will keep stalling. Is there a way to test the server qmail/mail queue to see if it isready to send another message? - rather than send it and have the script stall? It may be enough to simply be able to check that the number of messages left to be sent in the queue? Have search a lot for help on this with no results. Any server/qmail experts out there? Thanks Paul hello dear PHP-Fans - greetings to you - and a happy new year!! i set up a WAMP-System on my openSuse 11.4 system. In order to learn as much as i can bout PHP i want to do some tests and write some scripts. Well the WAMP is allready up and running. Now i try to give the writing access to the folder mkdir /srv/www/ where the php-scripts should go in... i want to give write permission to all to all files in /srv/www As root I generally: mkdir /srv/www/ chown <webmaster usrername> /srv/www/ /srv/www/ should be readable and traversable by all, but only writeable by it's owner (the user designated as the webmaster.) can i do this like mentioned above,... Love to hear from you greetings db1 So the server that host my website is not accepting .php files at the moment. I have a form mail in .php format, can anyone recommend an alternative form mail that will not use .php extension? Thank you kindly Hi i learnt today hard way that die(); can kill of loading the rest of your html page if you place it in the middle of your html after a few hours of trying to work out what was wrong and wondered what alternatives there are i have tried a few like "E_USER_ERROR" and "trigger_error" but none halt the script and display a message or do it without loading the rest of my page, There must be another way i just havent found it and would be really grateful if someone could tell me it. Thanks, Blink359 I have four check boxes that will determine how a search is conducted and I have retrieved the data through _POST[] The problem I have is how can I act upon the data returned? Each of the four text boxes could independently start a search but if I use an If statement the first choice will block the rest of the options eg. Code: [Select] if ($clientValue == "on"){ echo "perform a search based on above"; } Hi Everyone Does anybody know if there an alternative to preg_match? I cant get my head round regex so im having difficulty setting different preg matches. Is there an easier alternative? Thanks Is there a call_user_func_array() alternative other than eval()? With the shear genius of some of the individuals on this forum, I'd expect that if there is an alternative, someone here would know it. Any tips or insight greatly appreciated. Thanks Background (blah blah blah) I'm being kinda picky on efficiency and performance since I will be looking at possible hundreds of executions a request... so I'd like to avoid using the above mentioned functions since they take ~3x and ~10x longer (according to a this comment). i need to read a pdf and convert it to raw text (with line breaks - but that's as fancy as i need it)... pdflib does way more than i need, and it's super expensive, and i don't really see the need to install an app on my server just to read a simple pdf... there must be an alternative out there, but i can't seem to find it... and when all of php.net seems to reference pdflib, i start to get a little discouraged... it seems like a simple pdf reader class/package would be open source somewhere... any suggestions? thanks Hi all - I have a PHP form which allows users to submit data multiple times - in other words then can submit multiple records into the database using the same form over and over again. So currently how it works is once they've entered data and hit submit, the form refreshes and all fields get emptied, allowing the user to again enter more info. My client wants some sort of confirmation that data has been entered. I originally thought a simple pop-up/alert box saying 'Your data has been successfully entered' would do the trick since the user could then click 'ok', closing the pop-up to go about entering more data. However I hear a lot of disagreement on using javascript pop-ups due to pop-up blockers, javascript being turned off, etc. What alternatives exist to notify the user that their data has been submitted, while also allowing them to then continue entering more data? thanks! Steve Hi. I am coding a project, and ability to browse other websites through a frame in this site is central to the project. However, I need to be able to have the href of the frame's current location which I can't do using an iframe. Does anyone know of any techniques using server-side php in which one can view other sites and keep track of the location of the other sides? Thanks, Phil I want to encode a long string, and wish to make it shorter. base64_encode is very handy but it makes the string length longer. Is there an alternative to do the encoding/decoding with shorter encoded string length? So to stop third-party traffic on certain media files my site does, I did a download.php type script that just took in the media id, and found the filename and did a readfile on it for the user. The problem is that when you start doing massive amounts of traffic with it, I think the readfile stream is taking up a lot of cpu. Is there any alternative to readfile that creates a direct link between the user and the file, instead of it having to go through the php? I'm afraid that this is something I need to do on the server end, and not in PHP, but I figured I'd ask. Hey everyone, So I'm a complete PHP noob and have very basic knowledge of PHP - everything I learn is from tutorials online. I created a website which monitors Stock Exchange data for a particular stock exchange by downloading a CSV file from the Stock Exchange's website containing all the stock data - as this is the only way this particular exchange provides its data to 3rd parties. Now, my PHP system takes this CSV file, reads it and inserts the data into a MySQL database. Then, the function of my site is that users can create alerts for particular stocks that they are watching, and my website will send them an email when the stock price of the stock that they are watching goes above or below a particular value that they specify. Simple! However, since my MySQL database always needs the most recent version of the stock prices, the way I did this in the past was by using Cron every minute to download the file off the exchange's website, and insert the data into my database. I realise that this is quite inefficient, but my main problem is actually that the only way I can do cron every minute is by paying for my own Virtual Dedicated Server as normal shared hosting won't let me run a script that frequently. What I am here to ask is if any of you know an alternative way that I can constantly update the price data in my database i.e. an alternative to cron. I hear that you can run PHP scripts as 'daemons' but I'm not sure how this works nor whether I can do this with normal shared hosting. I cannot afford a Virtual Dedicated server any longer and so need a solution which is compatible with normal, cheap shared hosting. Any help would be much appreciated! I need to use something else than cURL to create the code to login to myspace accounts, I have to be able to enter postfields, Thanks I want a free alternative to 000webhost. I don't want to use something like xampp because eugh I don't get on with it. Thanks Hey guys. I currently have my website set up 'generating' php pages, rather than simply getting data off the database. Which is silly. I have no rectified that issue but end up with ugly urls such as http://www.worldwidelighthouses.com/Lighthouses/English-Lighthouses/Trinity-House-Owned/Lighthouse.php?Lighthouses=Beachy-Head Whats the best way to translate that into http://www.worldwidelighthouses.com/Lighthouses/English-Lighthouses/Trinity-House-Owned/Beachy-Head Im hopeless with apaches mod_rewrite... Many many thanks in advance. Danny Is there a way to do get_called_class for versions lower than php 5.3? |