Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. There is no PHP 6. As mentioned the MS-SQL extension is no longer available so you cannot use it. If you need to connect to a SQL Server database you need to use ither the SQLSRV extension from microsoft or the ODBC extension. You'll want to create a page consisting of: <?php phpinfo(); ?> and load that page on your host to see which functions and extensions are available to you.
  2. It's not so much that it's delayed, more that it's just be out-right cancelled. The big goal for PHP6 was full unicode support which would remove issues with utf8 and in generally make character encodings easier. The problem is that they couldn't find any good way to address the issues and I guess the library that they were planning to use to handle unicode was so large and complex that it was almost like they were embedding php into that library rather than that library into php. Since no real progress was being made, and they didn't like the library they just dropped it for now. Pretty much all the other features they had planned have been implemented now as of php5.4. They don't really see any need to make a PHP6 yet, and I am guessing they probably wont unless they get the full unicode feature implemented finally. I can't really think of anything at the moment that I'd want PHP to have. 5.4 covers it pretty well by adding short array syntax, <?= always available, function call array de-referencing/immediate object method calling. The only thing I think that might be nice still is a finally block and a way to declare two classes as friends. Operator overloading or some kind of __cast magic function might be nice. Making the built-in types objects might be nice but I don't think it is really that necessary. I like having the ability to do procedural programming, sometimes it easier to do something that way than the OOP way, especially for short one-time scripts you might create to solve a specific problem. I do things like that with some frequency. The fact that Java and C# force you to do objects for everything was something I always disliked about them. If the above mentioned operator overloading and/or __cast magic methods were implemented one could make object wrappers for types fairly easily, but you'd still have to call them manually on creation, eg $s=new String("blah"); rather than just $s="blah"; Might be nice to have, maybe a better alternative to my small desire to declare two classes as friends. Java's anonymous classes thing might be kind of nice too. I did like that about Java for the brief time I spent using it. Made implementing event handlers nice.
  3. Can you re-generate the csv file so it's in a proper format? If you have fields that have a comma in them they should be surrounded by quotes so that when the file is parsed the comma is treated as part of the string rather than as a field separator. Otherwise you can fix it by using file_get_contents, str_replace then file_put_contents.
  4. The issue is if you are using sessions (ie, call session_start()). PHP Locks the file that stores the session data so only one script/process can access it at a time. So if you make a request to coo.php and it starts the session then PHP locks the file. While it is sitting there doing it's polling your request to goo.php will be blocked at the session_start() call waiting for coo.php to unlock the session file so it can use it. There are three ways to avoid this problem. 1) Don't use session in your long poll scripts, not very useful as you often need the session data. 2) Call session_write_close() to end the session and free the file. Your $_SESSION variable will still exist but you won't be able to write to the session. 3) Implement your own session handler using something like Mysql or Memcached so that there is no longer an issue with locks. #3 would be the ideal solution. #2 will work in most cases since generally you only need to read the session data for login/user id details and not write anything.
  5. What is the exact error message you are getting? Make sure your error_reporting is set to E_ALL and that your not using the @ operator anywhere so you can see any warning PHP might throw.
  6. Setup the site on a new sub domain and configure your server to point that domain to a different public_html folder. Then just copy the contents verbatim to the new folder, and make whatever config changes you might need (like, db credentials).
  7. Didn't have them. Don't think I even knew of 7zip at the time (this was '03ish) and I knew WinRAR would do it but thought (assumed...probably) it was windows only and my desktop was Linux. It's not really that hard to make a file splitter anyway, only took like 30-45 minutes. Eventually I got a 128MB thumb drive to use and the next year they put internet in the dorms so only used it a couple times really. Now days I use 7zip if I need to split something.
  8. Aye, I have a function like that as well as a few others. I have them setup to check for an ENABLE_DEBUG constant too and only print/do stuff if it is defined and true. markTime() for benchmarking/timing: /* example use: markTime(); ..do stuff.. markTime(); ..do more stuff.. markTime(true); */ function markTime($finish=false, $lbl=null){ static $points=array(); static $collecting=false; if (!defined('ENABLE_DEBUG') || !ENABLE_DEBUG) return; if ($finish && $collecting && count($points) > 0){ $collecting=false; if ($lbl == null){ $lbl = count($points); } $points[] = array($lbl, microtime(1)); $firstPoint = reset($points); $lastPoint = end($points); ob_start(); printf("<div class=\"timerBlock\" onclick=\"this.className += ' show';\">\r\n"); printf("\t<p>Total Time: %0.3f seconds; Points: %d</p>", $lastPoint[1]-$firstPoint[1], count($points)); printf("\t<p>Points:</p>\r\n<ol>\r\n"); $previousPoint=null; foreach ($points as $p){ printf("\t<li>%s\r\n\t<ul>\r\n", $p[0]); printf("\t\t<li title=\"Since Start\">%0.3fs</li>\r\n\t\t<li title=\"Since previous\">%0.3fs</li>\r\n", $p[1] - $firstPoint[1], ($previousPoint)?$p[1] - $previousPoint[1]:'-' ); printf("\t</ul>\r\n\t</li>\r\n"); $previousPoint=$p; } printf("</ol></div>"); $content = ob_get_contents(); ob_end_flush(); if (defined('ERROR_LOG')){ $logDir = dirname(ERROR_LOG); $logFile = $logDir.DIRECTORY_SEPARATOR.'timer.log'; if (file_exists($logDir) && @touch($logFile)){ $fp = fopen($logFile, 'a'); fprintf($fp, "<p>URI:%s</p>\r\n<p>SELF:%s</p>\r\n", $_SERVER['REQUEST_URI'], $_SERVER['PHP_SELF']); fwrite($fp, rtrim($content)); fwrite($fp, "\r\n\r\n"); } } } else if (!$finish){ if ($lbl == null){ $lbl = count($points); } $points[] = array($lbl, microtime(1)); if (!$collecting){ $collecting=true; register_shutdown_function(create_function('', 'MarkTime(true);')); } } } dv() - basically var_dump() wrapped in <xmp></xmp> tags and controlled by the constant. function dv(/*...*/){ if (!defined('ENABLE_DEBUG') || !ENABLE_DEBUG) return; echo '<xmp>'; for ($i=0,$len=func_num_args(); $i<$len; $i++){ $arg = func_get_arg($i); var_dump($arg); echo "\r\n"; } echo '</xmp>'; } debug_print_friendly_backtrace() -- prints out a more friendly looking backtrace. function debug_print_friendly_backtrace($html=true, $return=false){ if ((!defined('ENABLE_DEBUG') || !ENABLE_DEBUG) && !$return){ return; } $info = debug_backtrace(); unset($info[0]);//First frame is this function call, ignore it. $frames=count($info); $retStr=''; if ($html){ $retStr .= '<div class="stackTrace"><p>Stack Trace ('.date('r').'):</p><ul>'; foreach ($info as $frameNum=>$frame){ $fn = $frame['function']; if (!empty($frame['class'])){ $fn = $frame['class'].$frame['type'].$fn; } $args=array(); if (isset($frame['args']) && is_array($frame['args'])){ foreach ($frame['args'] as $arg){ $args[] = sprintf("(%s) %s", gettype($arg), dpfb_stringify($arg)); } } $args = array_map(create_function('$a', 'return "<div class=\"arg\">".htmlentities($a)."</div>";'), $args); $retStr .= sprintf( "<li>#%d: %s(\r\n\t<div style=\"margin-left: 20px;\" class=\"argList\">%s</div>\r\n) (%s:%d)</li>\r\n", ($frames-$frameNum)+1, htmlentities($fn), implode(", ", $args), htmlentities($frame['file']), htmlentities($frame['line']) ); } $retStr .= '</ul></div>'; } else { $retStr .= "\r\nStack Trace (".date('r')."):\r\n"; foreach ($info as $frameNum=>$frame){ $fn = $frame['function']; if (!empty($frame['class'])){ $fn = $frame['class'].$frame['type'].$fn; } $args=array(); if (isset($frame['args']) && is_array($frame['args'])){ foreach ($frame['args'] as $arg){ $args[] = sprintf("(%s) %s", gettype($arg), dpfb_stringify($arg)); } } $retStr .= sprintf( "\t#%d: %s(\r\n\t%s\r\n) (%s:%d)\r\n", ($frames-$frameNum)+1, $fn, implode("\r\n\t, ", $args), isset($frame['file'])?$frame['file']:'-', isset($frame['line'])?$frame['line']:'0' ); } $retStr .= "\r\n"; } if ($return){ return $retStr; } else { echo $retStr; } } function dpfb_stringify($arg, $depth=2){ if (is_array($arg)){ if ($depth > 0){ $str = 'array('; foreach ($arg as $k=>$v){ $str .= '['.$k.'] => ('.gettype($v).') '.dpfb_stringify($v, $depth-1).', '; } $str = substr($str, 0, -2).')'; } else { return 'Array(len='.count($arg).')'; } return $str; } else if (is_object($arg)){ return get_class($arg); } else if (is_string($arg)){ $newstr = str_replace(array("\r\n", "\r", "\n", '"'), array('\r\n', '\r', '\n', '\"'), $arg); $ret = '('.strlen($arg).') "'.$newstr.'"'; return $ret; } else if (is_bool($arg)){ return $arg?'true':'false'; } else { return (string)$arg; } } I use the above fairly extensively during development. The enable debug flag is handy in case I forget to remove them before pushing out changes, the production servers don't define it so they don't output anything.
  9. Your other fields besides template_id would all be NULL unless you have some default clauses on your columns. The code doesn't really make much sense though, maybe explain what your attempting to do?
  10. Doesn't work with dynamic names. You'll probably just have to include the full namespace in the string rather than try and do a use statement.
  11. Regarding throw-away emails: I have on my VPS postfix setup so that I can send an email to $anything@test.example.com and it will forward it to my email address. That lets me just create whatever email I want so long is it has that extension. For example in my test copy of the database I do an UPDATE query to set all the user's emails to Firstname.Lastname@test.example.com Other than that I don't really have much for tools. For the most part things like cli php and chrome dev console are enough to get by with what I need. - See what a timestamp? (in ssh session) php -r "var_dump(date('r', 123456789));' - String length? (in chrome console) "some string".length - base64 decode? php -r "echo base64_decode('<paste string>');" - upper/lower a string? edit+ can do that - md5 a string? (in ssh) md5sum -<enter><paste string>^D^D Some kind of program or page that can do all this and more might be nice to have, I've not really found a need to create one or search for one though. The tools I have can do most tasks easy enough, or I can generally make a short php script to do what I need easy enough. The other day I needed to repeatedly base64 decode a bunch of different strings so I created this: $data=file('php://stdin'); foreach ($data as $d){ echo base64_decode($d), "\r\n\r\n"; } Then at the bash prompt I could just run php decode.php and paste all the strings one per line, then ^D and it would decode and output them all.
  12. I have a script that download my mutual fund finance data from the bank's site each morning and makes pretty graphs for me. I check it once in a while to see trends. I have data going back to late '09 that I can graph. Current trend is not so good I also have a script that will check the vudo 99c movie of the day and email me the info each morning so I can see if it's anything I want to watch. Saves me the trouble of remembering to go to the site and check. This one I actually put on my site with the ability for others to add themselves to the list just for the heck of it. Nobody actually has which is pretty much what I expected heh. I used to have other little apps I'd made but don't use them anymore, still got the code for most of them though somewhere. - UAccess -- Written in C using GTK+ this app was an always-on-top textbox that sat at the top of the screen. you could configure it to do things based on what you typed. By default it would open the browser to a google search of whatever you typed. I defined other things like a define: trigger that looked up the term in the dictionary. - EasyDict -- Used by the above, it was a small C/GTK+ tool that looked up a word and displayed the results. - Splitter -- Would take a large file and split it into multiple files of a specific size. Created this when I needed to move data from the PC's in the school's lap to my PC (no internet in the dorms at the time) and the only method available to me was a floppy disk.
  13. $_SERVER['HTTP_HOST'] will contain the hostname they used to connect, which will be the IP if you are doing something like http://12.34.56.78/ rather than connecting to a domain name. If you are using a domain name and just have the dns return different IP's then you should apply for your api key using the domain name, not the IP.
  14. Is the setting uncommented in the file (no ; before it)?
  15. I generally keep my sites in a SVN repository and will commit changes as I finish them. When it's time to update I just do a 'svn update' command on the server to download all the latest files. All the database/email/etc settings that vary based on environment are inside a config.inc.php file which is on the svn ignore list and not part of the repository (there is a template w/o any real values in the repository as config.inc.php.base). The updates are usually pretty quick as it only updates whatever has changed rather than having to upload every file. Changes to the config file are rare and just handled manually. Database changes I do manually prior to the file updates.
  16. fastcgi has it's own set of timeouts and checks to prevent it from stalling out on a locked up process. They would kick in if you for instance set php's execuction time limit to 0 (unlimited) then accidentally created an infinite loop. Or if you were running some other application besides PHP which didn't have any of it's own timeout protections and it failed.
  17. IIS will throw 500 errors rather than displaying the error under certain fastcgi configurations. The servers where I work do that. We just have to check the error log file whenever we see a 500 error to see what the error message is. It's a bit annoying but doesn't come up that often on those servers as most errors are caught on my dev environment which uses apache+mod php and displays them fine.
  18. The reason why prefork is the default on linux is likely due to compatibility reasons, though I can't say that for sure. Prior to apache 2 the prefork model was the only option I believe and it remains the default to maintain the same type of system as what apache used to be. The prefork method is also generally considered to be more stable as if something goes wrong and the worker crashes you only loose the one request/client it was handling. If a threaded worker crashes you loose all the requests/clients. The threaded mpm for linux takes some steps to help mitigate this by still forking a few separate processes and then having those processes create threads for processing. In such a crash you'd still loose a group of clients but not everyone. Another issue with using a threaded mpm is that you have to ensure your mod_php (and other modules) are thread safe which can sometimes be a problem. I'm not well versed in the subject but even though PHP does offer a thread-safe build I've heard some criticism that it's not really thread safe, just thread safe enough to get by in most cases without any major problems. *NIX systems have traditionally been processed based as far as I am aware as well. It is easy to work with multiple processes in *NIX systems and avoids some of the pain points of threads such as having to make sure two threads don't accidentally stomp on each others memory causing problems. It's been a long time since I really worked with a linux system at the lower levels but last time I did I seem to recall threading in linux was somewhat of a pain and not well supported/handled. It's probably better these days but the precedent has been set.
  19. By default apache on windows uses a threaded system which means it only has one process but several threads inside that process to handle the requests. As such there is less wasted memory as a lot of the code is shared between all the threads. On linux however apache defaults to using a fork base system for handling requests which means it has to fork off new processes for each of the concurrent requests. Forking a process is expensive memory wise as the entire set of process data is duplicated for each process. There are directives to control how many processes it will fork off to handle requests before it starts holding connections back. You would want to adjust these to whatever your vps can handle and whatever is reasonable for the amount of traffic you get. This is the default config for the fork system. # prefork MPM # StartServers: number of server processes to start # MinSpareServers: minimum number of server processes which are kept spare # MaxSpareServers: maximum number of server processes which are kept spare # MaxClients: maximum number of server processes allowed to start # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 150 MaxRequestsPerChild 0 </IfModule> StartServers controls how many processes it will create when you first start apache. These will be created and ready to process requests right away. MaxClients controls how many process apache will spawn maximum to handle concurrent requests. The rest of the directives control how apache manages the processes as far as creating and destroying them. Generally you do not need to change them from their defaults. So at any given time your setup could between StartServers and MaxClients copies of httpd running to handle requests. On my VPS a typical apache process seems to use around 10Mb of memory, so for each copy of httpd that gets started that is an additional 10Mb of memory being used. If my site got hammered and apache had to spin up all 150 (MaxClients) process then I'd be at 1500Mb of memory, or about 1.5 gig just for apache. It's possible to get a threaded apache setup on linux I believe but I've never tried it so I do not now how easy/hard it would be or how well it would operate.
  20. Increasing the limit mainly just means that a user can eat up more memory by posting a lot of data, but there are other directives to control this as well, such as max post size and memory limit. I'd say the risk in increasing it is fairly minimal. However, I'd also say if you have a page with 1k or more inputs, you might want to re-think the design and UI of that page as I'd guess there is most likely a better way to handle it.
  21. Correct. Long running scripts should not be run from a web-server anyway as it will tie up server resources for the duration of the script which can cause your server to be less able to serve normal requests.
  22. time spent in sleep() (and other outside-of-php things, eg db calls, exec() calls, etc) does not count toward the max_execution_time. That directive is a limit only on the time PHP itself is actually doing something. To test that directive you just need to create a busy loop of some sort. Something like this should do: <?php while (true){ sha1(time()); }; It will eat up your process for a while but should be killed once the max execution time is reached.
  23. You would have to remove your existing uploads folder and re-create it using PHP in order to do as suggested. Take the current folder and rename it to something else, for instance uploads.old. Then use the php script to create the new folder with the proper permissions, as well as copy over all the old files. Remove the old uploads folder when done.
  24. kicken

    CSS Wizardry

    I've kind off moved toward using a lot of classes for things but I do still use things like child or descendant selectors. I can see where avoiding them could have benefits though. I've been bit in the ass a couple times by specificity due to a rule higher up having a higher specificity than one further down due to including more elements in it's selector chain. My recent re-design of my personal site I've been setting up classes describing the content but might style it differently in the css based on where it is used. For example I have a class .author which I use to define the author name of an article/comment/whatever. I use this in a few different places: - div.published-by which is like a by-line area under an article title - <address> tag that denotes a signature at the end of an article. - div.comment which is for comments on an article. The author class has some generic styles like italic font but I will alter it as needed based on the location it is used in via css. It seems to work well so far and keeps me from having a bunch of separate classes all over the site. I do so little front-end work these days though, and what I do work on is so simplistic that I'm not sure my experiences are really worth that much overall lol.
  25. If you don't need the formatting then just output a CSV file. Have the first row be whatever heading values you want and the rest of the rows be the data. Here's a sample of some code I use for an export: $fp = tmpfile(); //Output headers $len = fputcsv($fp, array( 'Name', 'Invoice', 'ID', 'Notes', 'Record Type', 'For', 'Transaction Type', 'Date', 'Amount', 'Credits', 'Debits', 'Payments', 'Balance' )); foreach ($res as $row){ //Output data row. $len+=fputcsv($fp, array( $row['fname'].' '.$row['lname'], $row['invoiceNumber'], $row['invoiceId'], $row['invoiceNotes'], $row['recordTypeName'], $row['invoiceFor'], $row['transactionType'], $row['invoiceDate']->formatLocal('m/d/Y'), $row['invoiceAmount'], $row['credits'], $row['debits'], $row['payments'], $row['invoiceBalance'] )); } $outputFilename='invoices_'.$outputFilename.'.csv'; rewind($fp); header('Content-length: '.$len); header('Content-type: text/csv; charset=utf8'); header('Content-disposition: attachment; filename='.$outputFilename); fpassthru($fp); fclose($fp); exit;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.