[PHP] file_get_contents() can't fetch files via HTTP from localhost's vhosts
Hello all, I have a dynamically generated javascript library that I want to minigy with a PHP port of JSMin, in order to do that I need to first fetch the parsed PHP script that generates the JS (complete with comments and everything), and then minify it. The idea is to fetch the file via file_get_contents("http://www.vhost.dev/output.php";). This way the file gets parsed by PHP within the working environment (in respect of all paths, session policies etc..). It works flawlessly across domains, but it fails to fetch the file if the domain is a locally hosted apache vhost. Needless to say, I tried to add the host resolution to /etc/hosts, and lynx has no problem to fetch the page. if I try to execute a passthrough() with the command "php5-cgi /path/to/script.php" it breaks auth saving session files. Any idea how I can achieve parsing with php the contents of the script before manipulating it? (The script is too complex to assign it as a string to a php variable, which would otherwise empower me to minify it without further troubles). Thanks, Burn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: customer ids
blueboy ha scritto: Hi, I want to create random customer ids. I have an auto incremented coulumn but I would rather have a 6-8 digit/letter id randomly generated that can be used as a unique identifier across 3 tables. Does anyone have a algorithm to generate such a string and can you give the odds against 2 duplicate stings being generated? I know this is a strange ask. R. Here's how I do it, for 1 single table though.. you'll have to write yourself the mod to check on more tables. If you plan to have > 10 millions records make sure the maxrand is higher. When the "do" loop exits you have a unique id. function generateID() { $minrand = 1; $maxrand = ; $uniqueid[0] = mt_rand($minrand, $maxrand); $uniqueid[1] = $uniqueid[0]; return $uniqueid[1]; } do { //New ID generation $newid = generateID(); //Database check $sqlcheck = "SELECT youruniqueidhere FROM yourtablehere WHERE youruniqueidhere = '".$newid."'"; $conn = mysql_connect($db_host, $db_username, $db_password); mysql_select_db($db_name, $conn); $rs = mysql_query($sqlcheck, $conn); $rscount = mysql_num_rows($rs); } while ($rscount != 0); Cheers, Burn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: customer ids
Richard Davey ha scritto: Hi Burn, Wednesday, June 6, 2007, 3:55:21 PM, you wrote: Here's how I do it, for 1 single table though.. you'll have to write yourself the mod to check on more tables. If you plan to have > 10 millions records make sure the maxrand is higher. When the "do" loop exits you have a unique id. function generateID() { $minrand = 1; $maxrand = ; $uniqueid[0] = mt_rand($minrand, $maxrand); $uniqueid[1] = $uniqueid[0]; return $uniqueid[1]; } do { //New ID generation $newid = generateID(); //Database check $sqlcheck = "SELECT youruniqueidhere FROM yourtablehere WHERE youruniqueidhere = '".$newid."'"; $conn = mysql_connect($db_host, $db_username, $db_password); mysql_select_db($db_name, $conn); $rs = mysql_query($sqlcheck, $conn); $rscount = mysql_num_rows($rs); } while ($rscount != 0); Not that it is likely to occur on a low-traffic site, but the above approach is a race condition waiting to happen I'm afraid. It will however almost certainly satisfy the needs of the OP as long as his site stays off digg / slashdot :) Cheers, Rich Thanks for pointing it out, I'm well aware of it, but I use it in a back-end facility managed by a handfull of administrators, and an expected users base within the 100.000 units. The hit rate is 1:1 Perfectly reasonable with 5 possible concurrent threads running the code :) Worst thing that can happen is having mysql throw an error while trying to insert an ID that's already present in the database. It gets more complicated and unpredictable if the field isn't required to be unique at database design level. Wanting to make it perfectly safe the check should include the INSERT statement and continue looping till it's successful as well. Cheers! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: customer ids
Richard Davey ha scritto: Hi Burn, Wednesday, June 6, 2007, 4:39:05 PM, you wrote: Worst thing that can happen is having mysql throw an error while trying to insert an ID that's already present in the database. It gets more complicated and unpredictable if the field isn't required to be unique at database design level. Wanting to make it perfectly safe the check should include the INSERT statement and continue looping till it's successful as well. Or just wrap the whole thing in a stored procedure / transaction (it's what they were invented for after-all :), tasks like this should be pushed to SQL as much as possible imho. Cheers, Rich True, true :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php