Re: [PHP] Credit Card encryption
Billing Address (at least the street number) is used in conjunction with the zip code for AVS checks. On 5/31/10, tedd tedd.sperl...@gmail.com wrote: At 1:38 AM -0400 5/31/10, Paul M Foster wrote: On Sun, May 30, 2010 at 10:50:05AM -0400, tedd wrote: Besides, most credit card processing agencies even require that you use the customer's data (cc number, expiry date and CCS) to make the sale and then immediately dispose of it afterwards, usually within 24 hours under a signed agreement. Holding that information for more than 24 hours can be a criminal offense regardless of what type of hashing you use. Not true. It depends on the type of merchant and the situation. *blink* Not true and It depends are conflicts in logic. Either what I said is true or it isn't -- and if what I said is true for some (as it is and I can prove it) then what I said is indeed true. I'm curious, why say it's not true and then follow with it depends? It appears to me that you have your mind made-up and don't care to listen to our experiences and recommendations. That's Okay, but I'm simply telling you what I KNOW to be true. You may either accept what I have to say, or reject it, but to reply that what I say is Not true is somewhat offensive and confrontational. I hope you didn't mean it that way. :-) The PCI validation process allows for storage of all data except the 3-4 digit validation number. What I'm asked for at transaction time is the CC number, expiration date, digits for the billing address, and the billing zip code. And I can get the address and zip digits completely wrong and still have the transaction go through. Party true. What data are used in credit card transactions are the: name of the card holder, credit card number, expiration date, CCV number, and zip code. I have not dealt with any credit card processors that require the billing address -- they just use the zip code. Additionally, it is up to the client to determine the level of security they want. They *can* require that *all* information be correct before accepting a sale. The downside of not requiring *all* the data to be correct is that the rate the credit processor charges for the transaction rises. Simply and logically put, if you don't get all the information correct, then there is risk and that risk is passed on to the client via an elevated charge for processing -- look it up. The up-side of getting only the minimal data is getting a sale under a higher risk/rate -- that's the clients choice and they usually choose it. We've been doing it this way for 14 years and using the type of service you suggest would be expensive and impractical. Only in the last two years has PCI become more stringent in their requirements. And consequently, I'm having to re-evaluate how we store this particular information. Otherwise, our physical and other security is more than adequate. Yes, of course, if you have a machine gun or you're Kevin Mitnick, or you have a network of 20,000 bots pounding on my router, you're coming in anyway. Again, this is about *reasonable* security. You asked for opinions -- do what you want. :-) Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Sent from my mobile device -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Method documentation
I've seen @inheritDoc used in Java before, though I'm not sure about the php support. Waynn On 5/27/10, Adam Richardson simples...@gmail.com wrote: Larry, I've thought about this very issue before (java developers sometimes lament this issue, too), and I error on the side of duplication if I'm using inheritance. However, I'd say I rarely use inheritance for anything in my development, and I'm much more likely to use composition. When a project evolves that's built almost entirely using design patterns focused on composition, I find that I very rarely have to duplicate any documentation, or rework documentation later on because a completely new component is being used. Outside of PHP (Scala, Objective C, F#, etc.), it seems like inheritance is advocated much less frequently, due to the power and simplicity of composition (e.g., change behavior at runtime, requires less knowledge of the parent classes.) Quoting the Head First book on design patterns: Favor composition over inheritance Now, there are situations where either inheritance is the most appropriate, and/or the architecture is not directly under your control. And, as I said at the beginning, I tend to error on the side of duplication. I just try to never put myself in that situation :) Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com With the up-and-coming traits facility for PHP, it will be interesting on how this gets resolved for documentation readers. Indeed, I'm excited for the new capabilities, but they won't come easily in terms of the development ecosystem. -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com -- Sent from my mobile device -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Upgraded PHP now website doesn't work properly?
Emacs/xemacs does syntax highlighting too. On 1/10/10, Kaya Saman samank...@netscape.net wrote: Depending on the latency and bandwidth you could use X11 forwarding (granted the server supports it) so you could use a non-CLI editor. I think joe has some syntax highlighting, but I've never edited PHP files with it. If you are coming from a windows machine, you can use Cygwin or Xming to set up an X server on the box before SSHing to your data center w/X11 forwarding enabled. -Ken Sande Many thanks to everyone! I currently use a mixture of FreeBSD, Linux, and Solaris/OpenSolaris as operating systems so X11 forwarding is not a problem but maybe quite slow considering the distance between me and my data center right now, and also I have only 1Mbps upstream as the data center uses ADSL which is a restriction on my behalf. Am using SFTP to transfer non-html related stuff and using simple nano or copy-paste from the Gnome terminal. Yeah many options available I know and I guess that's what makes things fun :-) Anyway I'm sure I'll work something out, at worst case I could always VPN once I get a Cisco router out here and get an IPsec tunnel going and do things over NFS mount?? Regards, Kaya -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] User Account Management
Thanks so much for all the feedback! Ben's comment was something that prompted this discussion to begin with internally, in that we didn't want to reinvent the wheel, nor make a mistake in the security implenetation of our solution. I've forwarded this thread back internally, and we'll take this as a jumping off point for how to build our system. Waynn
[PHP] User Account Management
Hello all, We're building out a system that allows for user account creation/password management, and we're hoping to use existing open source software so we don't have to reinvent the wheel. I know of Drupal, and Zend Framework (and maybe CodeIgniter?), but do people have specific preferences for either, and recommendations for other products that I haven't heard of? It should just support basic account creation, being able to login/authenticate, change your password, storing user information like names and email addresses, etc. I tried searching for account management php but ended up getting a lot of CMS suites. Thanks, Waynn
Re: [PHP] Re: Buffered Logging?
Thanks for all the help! I'm going to try just writing to a database table first with INSERT DELAYED, and if there ends up being a performance hit, I'll use a MEMORY table that gets archived off every 5 minutes or so. Waynn
[PHP] Buffered Logging?
Hey PHPers, We've been doing sampled logging to the database in our application for awhile, and now I'm hoping eventually to blow that out to a larger scale. I'm worried about the performance implications of logging to our database on every single page load, though, so I was wondering if anyone's found a solution that does buffered logging. Essentially it would log to memory (memcached/apc/etc), and then periodically dump to a database in a structured format, preferrably user-defined. It's not essential that we get every signle hit, so I'd be fine if there was some data loss on a restart. I started writing my own solution, and then thought I'd ask the list to see if anyone has any experience with other tools that do this. My Google searches around buffered logging have mainly found error logging packages, like PEAR's Log package, or log4php. Those all seem to write to only one particular stream at a time, with no real support for buffering it in memory and then moving it to database. Thanks for any help! Waynn
Re: [PHP] Re: Buffered Logging?
Hey PHPers, We've been doing sampled logging to the database in our application for awhile, and now I'm hoping eventually to blow that out to a larger scale. I'm worried about the performance implications of logging to our database on ... If you are using mysql and MyISAM tables, you can try using insert DELAYED method. http://dev.mysql.com/doc/refman/5.1/en/insert-delayed.html This will bulk all your inserts for writes. Thanks for the suggestions! Those both look great for what I was going to do. One other thought I had after reading those suggestions, if we're doing web server logging, we can also parse the logs using webalizer or awstats. I know apache provides file size and the URL that's being hit, but what if I want to do custom referral tracking? We append ref=foo to our links to track where people are coming from, should I look at building my own solution for that, or do existing tools like awstats suffice for that as well?
[PHP] Editing PEAR packages
I wanted to makes some local edits to a PEAR package that I downloaded in order to build some custom functionality into it. What's the best way to manage this process to ensure that I don't accidentally blow away any changes if I update the package? Should I just copy the entire package to my own source repository, then use that directly instead of the PEAR package? And if I do it that way, is there an easy path to upgrade it? Waynn
[PHP] Re: Editing PEAR packages
Yeah, that's why I was hoping to maintain a separate install, since it would be easier to diff the patches. Shawn: Thanks for the suggestion to extend, I only wanted to make small changes to an existing function though, so it's harder to do it that way. My other thought was to refactor the underlying code base to make it easier. Waynn On 7/5/09, Greg Beaver g...@chiaraquartet.net wrote: Waynn Lue wrote: I wanted to makes some local edits to a PEAR package that I downloaded in order to build some custom functionality into it. What's the best way to manage this process to ensure that I don't accidentally blow away any changes if I update the package? Should I just copy the entire package to my own source repository, then use that directly instead of the PEAR package? And if I do it that way, is there an easy path to upgrade it? Best would be to follow Shawn's suggestion. If you do need to make changes, you should contribute them back to the package, PEAR is an open public repository, it may be incorporated and help others in your situation as well (this is the point of PEAR and of open source). Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] cannot figure out permissions for fopen/fwrite
The tmp folder isn't accessible from the web though, right? Someone would first have to get access to your server for that. On 7/1/09, Mari Masuda mbmas...@stanford.edu wrote: On Jul 1, 2009, at 12:54, Shawn McKenzie wrote: Mari Masuda wrote: On Jul 1, 2009, at 12:20, Shawn McKenzie wrote: Shawn McKenzie wrote: Mari Masuda wrote: Hello, This is probably a dumb newbie question. I am running PHP 5.2.5 and Apache 2.2.8 on my Mac Book Pro OS X 10.4.11. I compiled PHP and Apache from source a while ago (as opposed to using the built-in web server that is included w/ Mac OS X). I have written the below PHP whose purpose is to read an existing comma separated (CSV) file and save the data into a text file that I can later copy and paste from into my website content management system. The problem is that on my Mac, I cannot seem to figure out what permissions I need to set in order to make the input CSV and the initially non-existant output text file readable and writable by Apache/PHP. I have Googled and come across many pages about different ways to set permissions and different permissions to set but none of the ways suggested that I tried seemed to work for me. As a temporary solution, I uploaded my PHP file to a Windows 2003 server running Apache and PHP and it worked flawlessly (and makes me suspicious that there is some huge security hole with the Windows box since it was able to execute with no permissions modifications). Any tips would be greatly appreciated. Thanks! Mari --- start my code --- ?php $in = fopen(/Applications/apache/htdocs/wp-php/wp.csv, r); $out = fopen(/Applications/apache/htdocs/wp-php/tableToCutAndPaste.txt, w); $counter = 0; fwrite($out, table\n); while(($data = fgetcsv($in)) !== FALSE) { $paperNumber = $data[0]; $authors = $data[1]; $title = $data[2]; $filename = $paperNumber . .pdf; if(($counter % 2) == 0) { fwrite($out, tr\n); } else { fwrite($out, tr style=\background: #cc;\\n); } fwrite($out, tda href=\http://www.example.com/workingpapers/getWorkingPaper.php? filename=$filename\$paperNumber/a/td\n); fwrite($out, td$authors/td\n); fwrite($out, td$title/td\n); fwrite($out, /tr\n); $counter++; } fwrite($out, /table\n); fclose($in); fclose($out); ? --- end my code --- What are the permissions on /Applications/apache/htdocs/wp-php/ ? Apache needs write permissions on that dir in order to create the file tableToCutAndPaste.txt. It's probably not a secure idea to give write permissions to that dir, so maybe create a subdir of tmp and change those permissions (one way): mkdir /Applications/apache/htdocs/wp-php/tmp chmod a+w /Applications/apache/htdocs/wp-php/tmp Also, turn on error reporting so that you can see the exact problem. It may not be what you think. -- Thanks! -Shawn http://www.spidean.com Thanks for the suggestions. I added the following lines to the very top of my code: error_reporting(E_ALL); mkdir(/Applications/apache/htdocs/wp-php/tmp, 0777, true); chmod(/Applications/apache/htdocs/wp-php/tmp, a+w); and I also changed the line where it tries to open the file to write to to go to the new directory: $out = fopen(/Applications/apache/htdocs/wp-php/tmp/ tableToCutAndPaste.txt, w); Below are the errors I got: --- start errors --- Warning: mkdir() [function.mkdir]: Permission denied in /Applications/apache/htdocs/wp-php/generateTable.php on line 5 Warning: chmod() [function.chmod]: No such file or directory in /Applications/apache/htdocs/wp-php/generateTable.php on line 6 Warning: fopen(/Applications/apache/htdocs/wp-php/tmp/tableToCutAndPaste.txt) [function.fopen]: failed to open stream: No such file or directory in /Applications/apache/htdocs/wp-php/generateTable.php on line 9 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 13 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 22 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 27 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 28 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 29 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 30 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 35 Warning: fclose():
Re: [PHP] isset question
I notice that you're checking $_POST['mort'] but you're echoing $mort, is that your actual code? On 6/18/09, Gary gwp...@ptd.net wrote: I have a form that gives the submitter a choice or either one set of questions, or another. I am still getting the message even if the input was left blank. So on the line below, $msg.= isset($_POST['mort']) ? The mortgage amount is $mort\n : ; I get The mortgage amount is What am I missing here? Thanks Gary -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Field type for american money
For mysql, it's better to use int and then store it in cents (or micros) so you can use all integer operations instead of float ones. On 6/11/09, Shawn McKenzie nos...@mckenzies.net wrote: revDAVE wrote: Php - MySQL - newbie question - Field type for american money - int(11) seems to work fine - but also I tried decimal(10,2) Is one a better choice than another for american money usage? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] If you are only interested in round dollar amounts then int should work fine ;-) If you expect any fractions of a dollar (as I suspect you will), such as 19.95 then use decimal. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Field type for american money
Shawn McKenzie wrote: Waynn Lue wrote: For mysql, it's better to use int and then store it in cents (or micros) so you can use all integer operations instead of float ones. To each his own. Speed or otherwise I don't see a difference between: $total = 19.95 + 3.99; //shipping and $total = 1995 + 399; //shipping Except with the ints you have to format them for display. You have to format the floats too: ?php $total = 5.55 + 9.35; echo $total.\n; ? Oh, I didn't mean speed within PHP, I meant for mysql operations. I'm not sure how PHP handles int vs. float operations (though int is usually faster than float for other languages, isn't it?).
[PHP] Nagios Monitoring
Hey guys, I'm looking to write a nagios plugin that essentially monitors whether or not a database query returns a value 0 at any given point. I was hoping to write this in PHP, but I haven't found too many examples of Nagios plugins in PHP ( http://www.barryodonovan.com/index.php/2007/11/02/asterisk-pri-nagios is the best one I've found so far). Just wondering if anyone has any experience writing them? Waynn
Re: [PHP] Re: Fork and zombies
Whoops, I spoke too soon, I think the sleep(3) causes the child not to exit before the parent. If instead I don't pass WNOHANG to the waitpid command, it does error out. So it looks like your theory is correct, and I still have that problem. I guess the only solution is to rewrite the functions to use a new db connection every time? Each child should open its own database connection (if it needs one), and the parent should not keep the connection open at time of fork(). Yeah, that's what I ended up doing, and defining some global variables so that I could re-use the previous functions I created, thanks for the help! One other question I had, is pcntl_waitpid necessary in this case? Passing WNOHANG to it causes it to return immediately regardless of whether the child has exited or not, and my previous test when I didn't use pcntl_waitpid seemed to not leave any zombies as well. Would it be fine just to spawn off the child, and have the child exit at the end, and continue on my merry way with the parent without checking the status of the child? As a more general question, I'm worried that if I just keep the script as is, it's going to spawn off some crazy number of processes if I don't cap it. The first solution I came up with is to use a static variable in the parent thread, and then sleep every 20 threads or so. The most robust solution would be to build logic into the calling function to actually check for pids and only dispatch new threads when old ones had finished, but that requires changing multiple places, while this can be localised to just the dispatcher function. Does the first solution I propose seem sane? Waynn
Re: [PHP] /home/{user}/directory
bash also has $HOME, which maps to /home/USERNAME, just in case you wanted another way. :) On Tue, Mar 17, 2009 at 6:47 AM, George Larson george.g.lar...@gmail.comwrote: Thanks! On Tue, Mar 17, 2009 at 9:46 AM, Stuart stut...@gmail.com wrote: 2009/3/17 George Larson george.g.lar...@gmail.com In my scripts, I usually define a boolean constant DEBUG. True looks for local copies of includes and echoes queries as they're used. My question is: Is there any way for me to reflect the actual home folder of the person running the script? So it will be /home/george/foo when I run it but, for another user, it would be /home/their-username/foo? $dir = realpath('~/foo'); -Stuart -- http://stut.net/
Re: [PHP] Re: Fork and zombies
Yeah, that's what I ended up doing, and defining some global variables so that I could re-use the previous functions I created, thanks for the help! One other question I had, is pcntl_waitpid necessary in this case? Passing WNOHANG to it causes it to return immediately regardless of whether the child has exited or not, and my previous test when I didn't use pcntl_waitpid seemed to not leave any zombies as well. Would it be fine just to spawn off the child, and have the child exit at the end, and continue on my merry way with the parent without checking the status of the child? As a more general question, I'm worried that if I just keep the script as is, it's going to spawn off some crazy number of processes if I don't cap it. The first solution I came up with is to use a static variable in the parent thread, and then sleep every 20 threads or so. The most robust solution would be to build logic into the calling function to actually check for pids and only dispatch new threads when old ones had finished, but that requires changing multiple places, while this can be localised to just the dispatcher function. Does the first solution I propose seem sane? Waynn Actually, I just had another thought. I could take away the WNOHANG from pcntl_waitpid, and every 20 or so threads, wait for one to complete. It won't be precise, but it'll more or less queue them up in batches of 20 for sending.
Re: [PHP] Fork and zombies
Here's pseudo code for what I'm trying to do: foreach ($things as $thing) { info = getInfo($thing); // uses a db connection makeApiCall(info); } makeApiCall(info) { $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid\n; return; } else { // do some api calls exit; } } But after I spawn off the process, getInfo($thing) errors out sometime later on with an invalid query error, because I think the db connection is gone. I thought adding exit in the child process would be enough, but that doesn't seem to work, I still get the same error. Why would the child process affect the query in the parent process, especially if I exit in the child process? First things first - I would add a pcntl_wait like this: foreach ($things as $thing) { info = getInfo($thing); // uses a db connection makeApiCall(info); switch( $p=pcntl_wait( $stat, WNOHANG ) ) { case -1: echo some sort of error in pcntl_wait()\n; break; case 0: break; default: echo child $p finished\n; } } I actually tried this in the meantime: $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid waiting\n; pcntl_waitpid($pid, $status); if (pcntl_wifexited($status)) { echo finished [$status] waiting\n; return; } else { echo ERROR\n; } But it still has the same problem, and I'm also trying to avoid pcntl_wait or pcntl_waitpid at all because I still want to do it asynchronously. I even tried rewriting it do return $pid in the parent thread, and then aggregate them at the calling function level, and then loop through them all with pcntl_waitpid, but that didn't work either. Second, it sounds like you're expecting to reuse your database connection from getInfo() in the child you're forking in makeAPIcall()? I don't think that really works - I think you need a new connection per child. Oh, in this case, I don't do anything with the database at all in the child thread. I was worried there would be some errors there so I actually commented out all db accesses in the child thread, but it still somehow closes the parent's db connection (or at least causes the query not to work, somehow).
Re: [PHP] Fork and zombies
I think your waitpid() is in the wrong place, and at least you need use WNOHANG - unless you specifically want to wait for each child to finish before starting another one. But it still has the same problem, and I'm also trying to avoid pcntl_wait or pcntl_waitpid at all because I still want to do it asynchronously. pcntl_wait(WNOHANG) will make everything work asynchronously. Ah, I was changing it to waiting for each child to finish in order to see if I could narrow down my db problem, because I figure this should be more or less equivalent to running it synchronously. Even like this, though, it still causes the db problem.
[PHP] Re: Fork and zombies
(Apologies for topposting, I'm on my blackberry). Hm, so you think exiting from the child thread causes the db resource to get reclaimed? On 3/17/09, Per Jessen p...@computer.org wrote: Waynn Lue wrote: Ah, I was changing it to waiting for each child to finish in order to see if I could narrow down my db problem, because I figure this should be more or less equivalent to running it synchronously. Even like this, though, it still causes the db problem. I think the database problem is caused by your child inheriting the connection, and then closing it - whilst the parent is still using it. Your parent needs to open a new connection. /Per -- Per Jessen, Zürich (8.8°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Fork and zombies
Yeah, something like that. The connection is definitely closed when the child exits. I can confirm this. you definitely need to open a connection for each child process. if you require a db connection in the parent process, you should close it before forking (and then reopen it afterwards if you still need it). I thought that too, but this code seems to work, which seems to imply that the child doesn't kill the existing db connection. $conn = mysql_connect($sharedAppsDbHost, $sharedAppsDbUser, $sharedAppsDbPass, true); foreach ($things as $thing) { temp($thing); } function temp($thing) { global $conn; extract(getInfo($thing)); // this function call uses a shared db connection mysqlSelectDb($dbName, $conn); // dbName is a variable gotten from the above call $result = mysql_query(SELECT COUNT(*) FROM Users, $conn); $row = mysql_fetch_array($result, MYSQL_BOTH); echo $row[0]\n; $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid waiting\n; pcntl_waitpid($pid, $status, WNOHANG); if (pcntl_wifexited($status)) { echo finished [$status] waiting\n; return; } } else { echo child sleeping\n; sleep(3); echo child done\n; exit; } } == My main problem here is that I have a set of helper functions (getInfo is one of them) that uses a global db connection that exists in that helper script. Otherwise, I have to rewrite the function to create a new connection every time, which I'd like not to. Waynn
Re: [PHP] Re: Fork and zombies
Yeah, something like that. The connection is definitely closed when the child exits. I can confirm this. you definitely need to open a connection for each child process. if you require a db connection in the parent process, you should close it before forking (and then reopen it afterwards if you still need it). I thought that too, but this code seems to work, which seems to imply that the child doesn't kill the existing db connection. $conn = mysql_connect($sharedAppsDbHost, $sharedAppsDbUser, $sharedAppsDbPass, true); foreach ($things as $thing) { temp($thing); } function temp($thing) { global $conn; extract(getInfo($thing)); // this function call uses a shared db connection mysqlSelectDb($dbName, $conn); // dbName is a variable gotten from the above call $result = mysql_query(SELECT COUNT(*) FROM Users, $conn); $row = mysql_fetch_array($result, MYSQL_BOTH); echo $row[0]\n; $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid waiting\n; pcntl_waitpid($pid, $status, WNOHANG); if (pcntl_wifexited($status)) { echo finished [$status] waiting\n; return; } } else { echo child sleeping\n; sleep(3); echo child done\n; exit; } } == My main problem here is that I have a set of helper functions (getInfo is one of them) that uses a global db connection that exists in that helper script. Otherwise, I have to rewrite the function to create a new connection every time, which I'd like not to. Waynn Whoops, I spoke too soon, I think the sleep(3) causes the child not to exit before the parent. If instead I don't pass WNOHANG to the waitpid command, it does error out. So it looks like your theory is correct, and I still have that problem. I guess the only solution is to rewrite the functions to use a new db connection every time? Or maybe I should just sleep the child thread for long periods of time and hope the parent thread finishes in time (which admittedly seems really hacky)?
[PHP] Fork and zombies
I periodically run a script that makes a call against a remote API, which takes some time to return. In an attempt to increase thoroughput, I decided to investigate using pnctl_fork to spawn off multiple processes to make the call, since the slowest part is the network part of it (and waiting for the server response). I ended up writing a script that did this: $pid = pnctl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { echo parent $pid\n; return; } else { // make API call } While this works, it unfortunately leaves behind a zombie process every single time. I could rewrite this to instead call fork multiple times, then wait on all of them to return, but as my system is currently architected, the easiest way would be to fire and forget for this script. Does anyone have any ideas on the best way to do it? The other way I've done this is to use exec(php foo.php) and redirecting stdout and stderr to /dev/null. Waynn
Re: [PHP] Fork and zombies
Waynn Lue wrote: I periodically run a script that makes a call against a remote API, which takes some time to return. In an attempt to increase thoroughput, I decided to investigate using pnctl_fork to spawn off multiple processes to make the call, since the slowest part is the network part of it (and waiting for the server response). I ended up writing a script that did this: $pid = pnctl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { echo parent $pid\n; return; } else { // make API call } While this works, it unfortunately leaves behind a zombie process every single time. You need to call pcntl_wait() or pcntl_waitpid(). Right, but if I do that, then the parent has to wait until the child completes before it exits. Is there any way to have the parent exit before the child but prevent the zombie process for existing?
Re: [PHP] Fork and zombies
While this works, it unfortunately leaves behind a zombie process every single time. You need to call pcntl_wait() or pcntl_waitpid(). Right, but if I do that, then the parent has to wait until the child completes before it exits. No it doesn't - just call pcntl_wait() with WNOHANG to check the status of a child. Hm, so now I'm not so sure what's happening. Before trying your suggestion, I ran my script again without pcntl_wait so that I'd have a baseline for how many zombie processes are being created, and it turns out that I don't think any are. Previously, I was doing ps aux | awk '{ print $8 $2 }' | grep -w Z to find zombie processes, and it turns out that they existed from before, as the count didn't change after I ran my script. That leads to another problem, though, in that the resource for the database doesn't seem to be available for the parent after the child exits. Here's pseudo code for what I'm trying to do: foreach ($things as $thing) { info = getInfo($thing); // uses a db connection makeApiCall(info); } makeApiCall(info) { $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid\n; return; } else { // do some api calls exit; } } But after I spawn off the process, getInfo($thing) errors out sometime later on with an invalid query error, because I think the db connection is gone. I thought adding exit in the child process would be enough, but that doesn't seem to work, I still get the same error. Why would the child process affect the query in the parent process, especially if I exit in the child process? Following your suggestion, I also tried pcntl_wait in the upperlevel function, but still had the same problem. Thanks for any insight, Waynn
[PHP] Re: [PHP-DB] How important is your Express or Web Edition database? Please weigh in--
Yeah, that's definitely true. I've just been bitten too many times by a design that ended up being not flexible enough. :) Waynn On 2/28/09, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2009-02-28 at 16:08 -0800, Waynn Lue wrote: Plus, last time I checked, adding an enum required a full rebuild of the table, while having an auxiliary table allows it to happen much more quickly. Waynn On 2/28/09, Andrew Ballard aball...@gmail.com wrote: On Sat, Feb 28, 2009 at 5:13 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2009-02-28 at 01:04 -0500, Andrew Ballard wrote: On Fri, Feb 27, 2009 at 7:32 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I absolutely love enum datatypes; they allow you to use string values but internally stores them as numbers, and prevents the wrong data from being inserted. Much simpler than joining extra tables of values onto it. Oh, I know why programmers love them. I like them for a lot of the same reasons, but I'm enough of a DBA that I'm still not sure they are a very good idea in a SQL database. Granted, indexes on an ENUM column will be more useful than on SET columns, but what do you do when you need to add a value to the list? You have to have permission to modify the database, and you are limited to about 64 values. In some projects that's an acceptable constraint. I tend to like auxilliary tables better because I can easily add an admin interface to an app to allow users with sufficient permission to add their own values as needed without granting them access to muck around with the actual table structure, I'm NOT limited to 64 values, and indexes work even in 1:m (SET) cases in addition to 1:1 (ENUM) relationships. You can't add extra fields to an ENUM to track when a value was added to the list, whether it is no longer a valid value for new records (since it probably can't be deleted because of referential integrity), or any other information that might be relevant to the value. I know these aren't needed in every case, but I generally like to plan for extensibility if it doesn't require very much additional effort. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I'm not saying it is a replacement for auxiliary tables, but in a lot of cases, an enum works far better. Consider a column called display_status for a set of content pages. Having an enum type for 'live' and 'draft' is perfect, and likely not to change in the future. Using an external table is overkill, and reducing it to a number value that you then have to remember throughout your code doesn't make sense when the enum type makes it more logical. At the end of the day, it is down to personal taste, but I find a lot of good uses for enum, especially in CMS development. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-DB] How important is your Express or Web Edition database? Please weigh in--
Plus, last time I checked, adding an enum required a full rebuild of the table, while having an auxiliary table allows it to happen much more quickly. Waynn On 2/28/09, Andrew Ballard aball...@gmail.com wrote: On Sat, Feb 28, 2009 at 5:13 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2009-02-28 at 01:04 -0500, Andrew Ballard wrote: On Fri, Feb 27, 2009 at 7:32 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I absolutely love enum datatypes; they allow you to use string values but internally stores them as numbers, and prevents the wrong data from being inserted. Much simpler than joining extra tables of values onto it. Oh, I know why programmers love them. I like them for a lot of the same reasons, but I'm enough of a DBA that I'm still not sure they are a very good idea in a SQL database. Granted, indexes on an ENUM column will be more useful than on SET columns, but what do you do when you need to add a value to the list? You have to have permission to modify the database, and you are limited to about 64 values. In some projects that's an acceptable constraint. I tend to like auxilliary tables better because I can easily add an admin interface to an app to allow users with sufficient permission to add their own values as needed without granting them access to muck around with the actual table structure, I'm NOT limited to 64 values, and indexes work even in 1:m (SET) cases in addition to 1:1 (ENUM) relationships. You can't add extra fields to an ENUM to track when a value was added to the list, whether it is no longer a valid value for new records (since it probably can't be deleted because of referential integrity), or any other information that might be relevant to the value. I know these aren't needed in every case, but I generally like to plan for extensibility if it doesn't require very much additional effort. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with MySQL
You can type show create table tablename to see the datatypes. Waynn On 2/13/09, James Colannino ja...@colannino.org wrote: Hey everyone. I've been reading the list for a long time, but have only really posted to the mailing list a few times. I just had a quick question about MySQL. I'm not sure if this is exactly relevant to PHP, but it is for a PHP application I'm writing, so hopefully that makes this question ok :) Basically, I was wondering if there are any queries in MySQL that I can use to determine the data types used to construct a pre-existing table. The reason I ask is that I went back to look at the data in a table I've been using for a while and realized that I forgot to document what the data types were (DOH!) I'm sure there's something, but I wasn't quite sure what to google for, so I wasn't really able to turn up anything. Thanks! James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql_query and my.cnf?
Hey guys, I've been noticing that large queries cause a connection lost to mysql server problem, so I'm trying to figure out what settings I need to tweak in my my.cnf file to get it to work. I know people change the max-allowed-packet variable, but I'm trying to figure out what the correct section of the my.cnf is. Is it just [mysql]? Waynn
Re: [PHP] Foreign Keys Question
Waynn Lue wrote: As a side note, FKs do enforce other table specific properties like indexes on the fields being constrained, so they do add value there as well. But there's of course an extra cost on updates and inserts to see if the FK is violated. On the external table? No they don't. mysql create table t1(id int primary key, name varchar(255)) engine=innodb; Query OK, 0 rows affected (0.00 sec) mysql create table t2(t2id int, t1id int references t1(id)) engine=innodb; Query OK, 0 rows affected (0.00 sec) mysql show create table t2\G *** 1. row *** Table: t2 Create Table: CREATE TABLE `t2` ( `t2id` int(11) default NULL, `t1id` int(11) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) No auto-index on t2(t1id) at all. You have to define that yourself - you might want it part of a multi-column index for example. You definitely should index it, but it won't happen automatically. Hm, that's weird. Which version of mysql are you using? According to http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html: InnoDB requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan. In the referencing table, there must be an index where the foreign key columns are listed as the *first* columns in the same order. Such an index is created on the referencing table automatically if it does not exist. (This is in contrast to some older versions, in which indexes had to be created explicitly or the creation of foreign key constraints would fail.) *index_name*, if given, is used as described previously.
Re: [PHP] Foreign Keys Question
As a side note, FKs do enforce other table specific properties like indexes on the fields being constrained, so they do add value there as well. But there's of course an extra cost on updates and inserts to see if the FK is violated. Waynn On 12/11/08, Colin Guthrie gm...@colin.guthr.ie wrote: 'Twas brillig, and Chris at 12/12/08 01:20 did gyre and gimble: Micah Gersten wrote: Colin Guthrie wrote: The ON DELETE CASCADE option is key here... DELETE FROM students where student_id=1 will remove all traces of that student from the db... all the course they've attended, all the instructors who have taught them etc. keeps things nice and tidy without having to put the structure in your code all over the place. Col Why would you want to delete the instructors when deleting the student? I think he meant the link between the student instructor (in the student_instructor table), not the instructor itself. lol, indeed, that's what I meant... Sorry I thought it was implied in the context! Say you have the following layouts instructors: instructor_id, name students: student_id, name instructor_students: instructor_id, student_id This structure would hold a list of instructors and a list of studends and also a one to many mapping of instructors to students. If you delete a student the FK can cascade to the instructor_students table and thus delete the records that indicate a given instructor (or instructors) taught them. Col -- Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Stack Trace Length for Exceptions
I've been adding in exceptions at various points in the code so that I can more easily track where things are breaking and through which code path, but I just ran into a problem where it seems that the full stack trace isn't showing up in the error_logs. When I check out the logs, it only shows the last three frames, but I'd like it go all the way up the stack. Is the only solution to use something like debug_backtrace() instead, or is there some setting to change what gets printed to the error log? Thanks! Waynn
[PHP] Re: phpDesigner 2008?
All in one--is the other better? On 11/18/08, Nathan Rixham [EMAIL PROTECTED] wrote: Waynn Lue wrote: I know the IDE wars spring up occasionally, but looking through the archives, I haven't seen any discussions pro or con for phpDesigner 2008 ( http://www.mpsoftware.dk/phpdesigner.php). Anyone had a chance to use it and think it's good or not? I just installed PDT + Eclipse today, and I'm still getting used to the integration. I'm used to Eclipse + Java, so it somewhat throws me for a loop in trying to figure out what works in what scope. I do wish I could have it do some kind of analysis of my files plus dependencies so any problems could be discovered at compile time, rather than run time. Thanks, Waynn php isn't pre-compiled though.. did you go for ganymede with pdt 2 or the all in one? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] phpDesigner 2008?
I know the IDE wars spring up occasionally, but looking through the archives, I haven't seen any discussions pro or con for phpDesigner 2008 ( http://www.mpsoftware.dk/phpdesigner.php). Anyone had a chance to use it and think it's good or not? I just installed PDT + Eclipse today, and I'm still getting used to the integration. I'm used to Eclipse + Java, so it somewhat throws me for a loop in trying to figure out what works in what scope. I do wish I could have it do some kind of analysis of my files plus dependencies so any problems could be discovered at compile time, rather than run time. Thanks, Waynn
[PHP] General Mysql Connect
I sent an email to the mysql list, but it reminded me of a question I had for people structuring their PHP code. What's the general way that people structure their connections? Right now, I spawn off two mysql_connect calls at the top of the file that includes my database calls, using true for the fourth parameters, so as to create two new connections. Then I use those two connections for two different databases I have to query from. Is it better just to use mysql_select_db within the query function every time for the same connection? Should I use mysql_connect every time without using true, so as to re-use connections. Should I be using pconnect instead? I spent some time looking for answers to these questions, but am getting conflicting answers. Some people think relying on the re-use of these functions is good, some think that explicit management is better. In general, how have people on the list found them? For example, is having constant mysql_select_db calls a problem? Thanks, Waynn On Wed, Oct 29, 2008 at 2:47 AM, Waynn Lue [EMAIL PROTECTED] wrote: We've started seeing mysql errors in the logs, and when i look at the output of mysql_error() (in php), i get lost connection to mysql server during query. Here's an example stack trace: 'Can't connect to name database [Lost connection to MySQL server during query]' Similarly, we're seeing stack traces here as well: 'Can't connect to name database []' I usually only see this mesasge when I don't use a connection for awhile and it timeouts, but in this case, the connection is only opened for the duration of a script, which can't be running for more than a second. The mysql error logs don't show anything, and wait_timeout is set to 28800. At first, I thought it was because I was calling mysql_select_db too much, so I ended up using two mysql connections per page load, but that didn't seem to change anything. How can we prevent this error from happening, what else can I do to diagnose this further? Google brings up some more discussions about it, but nothing seems related to this, like packetsize. This is happening when we select two ids from a database. And SHOW PROCESSLIST shows that the number of connections aren't even coming close to max connections. Thanks for any advice, Waynn
[PHP] Re: General Mysql Connect
Yeah, it's the same user, same everything (for now). But I wonder why we're seeing these lost connection errors and I'm trying to fix it--this was one of the things I was investigating. On 10/29/08, Chris [EMAIL PROTECTED] wrote: Waynn Lue wrote: I sent an email to the mysql list, but it reminded me of a question I had for people structuring their PHP code. What's the general way that people structure their connections? Right now, I spawn off two mysql_connect calls at the top of the file that includes my database calls, using true for the fourth parameters, so as to create two new connections. Then I use those two connections for two different databases I have to query from. Is it better just to use mysql_select_db within the query function every time for the same connection? Should I use mysql_connect every time without using true, so as to re-use connections. Should I be using pconnect instead? I spent some time looking for answers to these questions, but am getting conflicting answers. Some people think relying on the re-use of these functions is good, some think that explicit management is better. In general, how have people on the list found them? For example, is having constant mysql_select_db calls a problem? Are they connecting as the same user and on the same server? Then you can replace with a mysql_select_db call. If they aren't both of those, you have no choice. No idea if it'll make much of a difference (performance wise etc) but I'd leave it as two connections. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: General Mysql Connect
It's actually a deliberate design decision to have two dbs, because one's a shared database, and one's application specific. Thanks, Waynn On 10/29/08, Ashley Sheridan [EMAIL PROTECTED] wrote: On Thu, 2008-10-30 at 08:55 +1100, Chris wrote: Waynn Lue wrote: I sent an email to the mysql list, but it reminded me of a question I had for people structuring their PHP code. What's the general way that people structure their connections? Right now, I spawn off two mysql_connect calls at the top of the file that includes my database calls, using true for the fourth parameters, so as to create two new connections. Then I use those two connections for two different databases I have to query from. Is it better just to use mysql_select_db within the query function every time for the same connection? Should I use mysql_connect every time without using true, so as to re-use connections. Should I be using pconnect instead? I spent some time looking for answers to these questions, but am getting conflicting answers. Some people think relying on the re-use of these functions is good, some think that explicit management is better. In general, how have people on the list found them? For example, is having constant mysql_select_db calls a problem? Are they connecting as the same user and on the same server? Then you can replace with a mysql_select_db call. If they aren't both of those, you have no choice. No idea if it'll make much of a difference (performance wise etc) but I'd leave it as two connections. -- Postgresql php tutorials http://www.designmagick.com/ How difficult would it be to converge the 2 databases into one? This would obviously use less memory (not sure exactly how big the footprint of each connection is though) and will slightly speed up page display time (as you only have to wait for one connection to be made rather than two) Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] General Mysql Connect
With MySQL, you can change the DB from query to query with mysql_select_db. The alternative as I stated in my last post is to use the fully qualified table name (database.table) in your query. MySQL doesn't care which DB you have open if you do that. In both of these cases, the same connection is used. That brings me back to the original point, is there a performance decrease to continually calling mysql_select_db? And shouldn't connections that are being made during the processing of a php script (which runs for no more than two seconds) be lasting at least until the end of the script, instead of getting errors like Lost connection to server?
[PHP] Re: General Mysql Connect
Waynn Lue wrote: Yeah, it's the same user, same everything (for now). But I wonder why we're seeing these lost connection errors and I'm trying to fix it--this was one of the things I was investigating. Random guess :) You're overwriting a result or connection variable? $query = select * from db1.table1; $result = mysql_query($query, $conn1); while ($row = mysql_fetch_assoc($result)) { ... $result = mysql_query(select * from db2.table2, $conn2); } It's possible, but seems unlikely because the problem only comes up periodically, not deterministically.
Re: [PHP] Flags package for PHP?
Thanks for the advice! I had initially tried it and couldn't seem to get getopt2 working (and getopt was supposedly deprecated), but eventually found a good example here: http://www.sitepoint.com/article/php-command-line-1/3/ On Thu, Oct 16, 2008 at 10:31 AM, Jim Lucas [EMAIL PROTECTED] wrote: Waynn Lue wrote: I'm running some command-line scripts that are taking more and more arguments, and I'm wondering whether anyone's used a good flags package for PHP? Support for string/int/boolean arguments would be nice, otherwise I'll just hack together my own. Thanks for any advice, Waynn I would maybe look into using a standard ini file and then use the parse_ini_file [1] function to bring it all together again. 1 - http://us2.php.net/manual/en/function.parse-ini-file.php -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare
Re: [PHP] logic for grabbing what we need from user-input addresses for AVS?
AVS generally only exists for us and canada and parts of the uk, if I remember correctly. Usually they're just looking for the beginning part of the street address, not the concatenation or anything else like that. No need for apartment numbers, for example if you're just looking at avs. If you're doing a full credit card auth, though, that's a different matter. Waynn On 10/18/08, Govinda [EMAIL PROTECTED] wrote: Hi all This is not exactly PHP, but an issue that we have to work out in code (whatever we use) - I am working on a shopping cart site which will have orders from any country. To cut down on fraudulent orders, our cc processor (whatever we call them), to enable Address Verification System (AVS), accepts a var/ value which is The numeric portion of the street address. It is Required for AVS. Now to get this from what the user input, I can: - just read the *numeric* characters off the front of the first (of 2) address text inputs, stopping grabbing them once I reach any non- numeric char., or I could - get *any* numeric chars input in that text area and concatenate them all together (if there is more than one continuous run of them), or - get *any* numeric chars input in *either* of the address text areas and concatenate that all together (if there is more than one continuous run of them), or - (what are the other possibilities?) I am asking you guys/gals using AVS: what are they looking for? The docs make this clear that they want: The numeric portion of the street address, but just because I can't think of addresses that don't match a pattern I am thinking of does not mean they don't exist or are not valid. And how should the logic of my algorithm be written if it was just for USA addresses? ... and more importantly - if I am writing it to handle addresses from any country? Thanks for any insight/logic based on experience, ;-) -Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Sent from my mobile device -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Flags package for PHP?
I'm running some command-line scripts that are taking more and more arguments, and I'm wondering whether anyone's used a good flags package for PHP? Support for string/int/boolean arguments would be nice, otherwise I'll just hack together my own. Thanks for any advice, Waynn
[PHP] date_default_timezone_set and Time Zones
I'm using date_default_timezone_set(America/Los_Angeles) in my code, then I output it like date(m/d/y, H:i:s, O, some unix timestamp); But even though it's daylight savings time in Los Angeles, I get output like [01/31/08, 23:00:00, -0800] Shouldn't it instead be -0700? Am I misunderstanding how these timezones work? Waynn
Re: [PHP] date_default_timezone_set and Time Zones
Is it daylight savings time in LA on 31 January? Wow, yeah. That makes sense, for some reason I was thinking of it in terms of today, but of course that can't be right. Thanks for that clarification, not sure what I was thinking. :)
Re: [PHP] PHP + Cron jobs
On Mon, Sep 29, 2008 at 9:34 AM, Richard Lynch [EMAIL PROTECTED] wrote: If you are running PHP as CGI, replacing the CGI with CLI could be problematic down the road... Right, and I am, so I stayed away from that solution. My next attempt was to specify /usr/local/bin/php in the cron job, but that led to a problem because of the include paths. Now that I specific the full path, evidently the include path no longer is relative to the directory that's being executed from, and so it fails to execute. One solution is to also include the executing directory in the php script itself, I assume, but is there any better solution than that? If not, I went ahead with Richard's suggestion to use -q. Assuming a Google search is correct (since man php and php -help don't mention -q), that just suppresses the HTML headers from being sent? Thanks again, Waynn
[PHP] Re: PHP + Cron jobs
Oh, I thought having one for cgi and one for cli was common. Do people generally run only one, regardless of whether they're hitting it from a webserver or running it from the commandline? Thanks, Waynn On 10/1/08, Per Jessen [EMAIL PROTECTED] wrote: Waynn Lue wrote: Right, and I am, so I stayed away from that solution. My next attempt was to specify /usr/local/bin/php in the cron job, but that led to a problem because of the include paths. Now that I specific the full path, evidently the include path no longer is relative to the directory that's being executed from, and so it fails to execute. One solution is to also include the executing directory in the php script itself, I assume, but is there any better solution than that? I would take a look at your core problem - why do you have php executables in both /usr and /usr/local? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to submit form via PHP
Hm, it specifies base though. Does that mean the full query string won't be guaranteed to be passed along? On 9/29/08, Lupus Michaelis [EMAIL PROTECTED] wrote: Ashley Sheridan a écrit : From the link you gave, we stick on http://www.w3.org/TR/html401/types.html#type-uri, so it references an IETF RFC http://www.ietf.org/rfc/rfc1808.txt that describes what is an URI. The fourth section describes how we have to determine the resolution of an URI. The point that are in our scope is the next I quote : « a) If the embedded URL is entirely empty, it inherits the entire base URL (i.e., is set equal to the base URL) and we are done. » If you have any doubt, just enjoy reading the full document ;) But for me, it is quite clear that an empty string is a valid URI *into* a document served by HTTP. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + Cron jobs
Yup, you're completely right. I checked the cronjob and got this: PHP 5.2.6 (cgi) (built: Aug 11 2008 13:39:32) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle Turns out there's /usr/bin/php, which is the cgi version, and /usr/local/bin/php, which is the cli version. So I see three possiblities. 1. Change the shebang on the php script itself, 2. change the crontab to reflect to path I care about, or 3. replace /usr/bin/php. I'd prefer the 3rd, but does that cause problems for me in my actual web pages? Thanks, Waynn
[PHP] PHP + Cron jobs
This is something that I've noticed for awhile, but last post to this mailing list reminded me that someone probably already knows how to work around this! I have a cron job that looks something like 12 6 * * * php /home/foo/temp.php But even if temp.php doesn't output anything, I still get emails from the crontab that consist of Content-type: text/html I assume this is happening because it's interpreting as a web page or some such. Is there a better way to set the crontab so I don't get that output? Thanks, Waynn
Re: [PHP] PHP + Cron jobs
This is something that I've noticed for awhile, but last post to this mailing list reminded me that someone probably already knows how to work around this! I have a cron job that looks something like 12 6 * * * php /home/foo/temp.php But even if temp.php doesn't output anything, I still get emails from the crontab that consist of Content-type: text/html I assume this is happening because it's interpreting as a web page or some such. Somehow your /home/foo/temp.php isn't running with the correct PHP interpreter. Is there a better way to set the crontab so I don't get that output? You can always use MAILTO= to direct any output from a cronjob. I actually am using MAILTO, and that's where the problem is. A cronjob only mails when there actually is output, which I'm fine with. In fact, when I run php temp.php from the command line, I don't get any output. But when it's part of the cronjob, there's that content-type output, which triggers mail to me. You mentioned a correct php interpreter above. Should I instead be running php through some other way or with a specific flag? Waynn
Re: [PHP] PHP + Cron jobs
Hm looks like it's CLI. $ php -v PHP 5.2.6 (cli) (built: Aug 11 2008 13:36:00) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle
Re: [PHP] How to submit form via PHP
No it doesn't... without an action statement... Sorry to drag up an old thread, but I just saw this. Is that true of all browsers? I'm wondering because I just coded a site to use this behavior, then I saw that the html specification says the action attribute is required. Thanks, Waynn On 8/15/08, Robert Cummings [EMAIL PROTECTED] wrote: On Fri, 2008-08-15 at 13:30 -0500, Jay Blanchard wrote: [snip] Hello. I'm pretty noob in PHP and would like to know how can I submit some HTML form got via file_get_contents(URL). For example: form name=someform method=post input type=submit /form so how can I submit 'someform' form. Thanks in advance for any suggestions. [/snip] Click 'Submit' Your form tag needs an action statement No it doesn't... without an action statement it will submit to the same URL in which it was presented. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Passing Variables to an iframe
This may be more a general HTML question, so let me know if I should post somewhere else. I was hoping to do some logic in a script, and then pass the results of that script to an iframe for more processing. Is it secure to include those variables as get parameters to the iframe, though? In other words, if I have something like this: iframe src=http://example.com/?accesseverything=true; where I use PHP to generate the src for the iframe. Could someone just use Firebug or something to set that variable? Is there a better way of passing it instead? Thanks, Waynn
Re: [PHP] Passing Variables to an iframe
Ah, that makes sense. Given all the input on this thread, I'll see if I can get sessions do what I want. Thanks! Waynn
Re: [PHP] FW: [SPAM] [PHP] FIFO files on PHP?
On Wed, Jul 2, 2008 at 1:22 AM, Chris Scott [EMAIL PROTECTED] wrote: -Original Message- From: Waynn Lue [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 01, 2008 11:06 PM To: php-general@lists.php.net Subject: [SPAM] [PHP] FIFO files on PHP? Importance: Low I'm trying to build a queue out using FIFO files (someone on the MySQL list suggested checking them out instead of using the database), but I'm running into a problem because of the synchronous fwrite call. Here's the code: $fifoFile = '/tmp/fifo'; if (!file_exists($fifoFile)) { posix_mkfifo($fifoFile, 0600); } $fp = fopen($fifoFile, w); fwrite($fp, content); fclose($fp); But this will block until something actually reads the pipe. Is there any way to write to the pipe, then go away as opposed to waiting until something consumes it? Otherwise, I may just go back to a database table. Thanks, Waynn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Fifo nodes are equivalent to a pipe (|) and have no size on the file system and therefore the write won't finish until some process reads from the node. See the man page http://linux.die.net/man/7/fifo . Wow, my mail client filtered these responses so I only just noticed them--I thought there were no responses. Thanks for letting me know, I ended up using threads to accomplish something similar.
Re: [PHP] Version Control Software
Does subversion meet your needs? You can check out a working copy that's your dev copy, then check in changes and push to production whenever you want. Waynn On 8/6/08, Benjamin Darwin [EMAIL PROTECTED] wrote: After reading a topic on the list here about someone losing their website, and having a minor mistake on my own that cost me a week's work on a file (basically, tested the file, then uploaded to the live site and took the daily backup off the live site.. only to find the file was messed up.. and had to go to the weekly backup off cd to recover it, losing a week of work).. I'm wondering if anybody knows of a version control software program that may fit my needs. Basically, I'm looking for something that runs locally, not on the live site, that I can edit the files on the dev computer, and store old versions on the dev computer, and then just publish off of the local onto the live site whenever I need to. Anybody have any suggestons/ideas on how this should be done, and what program is a good fit? Thanks for any help, Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Memory Management
Waynn Lue wrote: I've been running the script below: ?php $appIds = getLotsOfAppIds(); foreach ($appIds as $appId) { echo $appId\n; //echo memory_get_usage() . \n; try { $getBundles = getBundles($appId); $numBundles = count($registeredBundles); echo $numBundles . \n; continue; } } ? And I get PHP Fatal Error: Allowed Memory Size Exhausted after it runs for a bit. Looking at the memory usage, it's because $getBundles (an array) is huge, and keeps growing. What I'm confused by is why setting it to something else in the next iteration of the foreach loop doesn't free the previously allocated array, since there shouldn't be any more references to it. I've worked around it by explicitly calling unset($getBundles), but just wanted to understand why it's working the way it does. Aside from on the 1st iteration, each time getBundles() is called, it creates an array within its own scope. Until PHP assigns the returned array to $getBundles, there are two in memory. Maybe that's the problem. But that means that as soon as you move to the next iteration of the foreach loop, both arrays should still go away, right? Instead, it looks like the memory is continuously increasing on each iteration. I don't know how you can stand naming structures or variables the same as functions, btw. That would drive me nuts. Where is this $registeredBundles coming from? Perhaps you meant: $registeredBundles = getBundles($appId); Ah, my fault. Yeah, I don't usually name variables the same as functions, but was coming up with names on the fly as I tried to shrink my script down to a reproducible test case. It should have been ?php $appIds = getLotsOfAppIds(); foreach ($appIds as $appId) { echo $appId\n; //echo memory_get_usage() . \n; try { $registeredBundles = getBundles($appId); $numBundles = count($registeredBundles); echo $numBundles . \n; continue; } catch (Exception $e) { echo exception caught\n; } } ? and unset($registeredBundles).
[PHP] PHP Memory Management
I've been running the script below: ?php $appIds = getLotsOfAppIds(); foreach ($appIds as $appId) { echo $appId\n; //echo memory_get_usage() . \n; try { $getBundles = getBundles($appId); $numBundles = count($registeredBundles); echo $numBundles . \n; continue; } } ? And I get PHP Fatal Error: Allowed Memory Size Exhausted after it runs for a bit. Looking at the memory usage, it's because $getBundles (an array) is huge, and keeps growing. What I'm confused by is why setting it to something else in the next iteration of the foreach loop doesn't free the previously allocated array, since there shouldn't be any more references to it. I've worked around it by explicitly calling unset($getBundles), but just wanted to understand why it's working the way it does. Thanks, Waynn
Re: [PHP] Math Weirdness - Can it be done with integers alone??
There's an algorithm known as banker's rounding that I thought all US banks used. I'm on blackberry right now so I don't have a pointer, but essentially you round to the nearest even cent. 1.5 goes to 2, as does 2.5. Waynn On 7/15/08, tedd [EMAIL PROTECTED] wrote: At 4:15 PM -0400 7/14/08, Robert Cummings wrote: Nope, banks can't round like that when calculating your daily interest :) Cheers, Rob. I do know that when it comes to interest you pay them, they round up. When it comes to interest they pay you, they round down -- and why not? A decision has to be made -- you can't pay someone less than a penny. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Asynchronous PHP Execution
On Sat, Jul 5, 2008 at 12:28 PM, Daniel Brown [EMAIL PROTECTED] wrote: On Sat, Jul 5, 2008 at 6:01 AM, Waynn Lue [EMAIL PROTECTED] wrote: I have a system where a user clicks on a button which causes rows to be inserted in to the database. I'd also like to run some lengthier post-processing on those rows, but don't want to put it in the critical path of the rows being inserted and returning to the user. What's the best way to either batch up these other actions, or pass them to a thread or other asynchronous process to do the second part of the action? Can you just run this via a cron or Scheduled Task? Just have a boolean column that distinguishes new rows as unprocessed, and flip the flag when the cron script processes the row. The problem with that is it requires another column to a table, which across all our databases will take a really long time. The other way is to create another table, which means we're inserting across multiple tables. Waynn
Re: [PHP] Asynchronous PHP Execution
and exec/shell (but that doesn't seem to be asynchronous), but neither seems optimal. It can be if you redirect the output streams and put an ampersand after it: ?php exec('sleep 5 /dev/null 2/dev/null '); echo 'Script ended'; ? This tiny sample should end immediately, and the sleep command should run on regardless. Thanks so much for the suggestion, that's what I ended up doing and it worked, after some fiddling. Just as a side note, does it execute from the current directory of the file? Previously, I tried calling exec('php scripts/foo.php'), but it seemed like there was some weird interaction between different required files. E.g., this was the layout: orig.php scripts/foo.php incl.php orig.php had the exec line, and foo.php had require_once(../incl.php). But it seemed like the exec call caused foo.php to execute from the scripts directory while the require_once caused incl.php to also execute from the scripts directory. How does php determine what the working directory is?
[PHP] Asynchronous PHP Execution
I have a system where a user clicks on a button which causes rows to be inserted in to the database. I'd also like to run some lengthier post-processing on those rows, but don't want to put it in the critical path of the rows being inserted and returning to the user. What's the best way to either batch up these other actions, or pass them to a thread or other asynchronous process to do the second part of the action? I've thought about using a queue, either backed by a FIFO file (which is proving somewhat difficult) or MySQL, and exec/shell (but that doesn't seem to be asynchronous), but neither seems optimal. Does anyone have any suggestions? Thanks, Waynn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] FIFO files on PHP?
I'm trying to build a queue out using FIFO files (someone on the MySQL list suggested checking them out instead of using the database), but I'm running into a problem because of the synchronous fwrite call. Here's the code: $fifoFile = '/tmp/fifo'; if (!file_exists($fifoFile)) { posix_mkfifo($fifoFile, 0600); } $fp = fopen($fifoFile, w); fwrite($fp, content); fclose($fp); But this will block until something actually reads the pipe. Is there any way to write to the pipe, then go away as opposed to waiting until something consumes it? Otherwise, I may just go back to a database table. Thanks, Waynn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Good XML Parser
Ok, thanks so much for the help. I went with DOM-parsing to begin with, I'll explore XPath + SimpleXML later. Thanks, Waynn On Mon, May 12, 2008 at 5:23 AM, David Otton [EMAIL PROTECTED] wrote: 2008/5/12 Waynn Lue [EMAIL PROTECTED]: So if I'm looking to parse certain attributes out of an XML tree, if I use SAX, it seems that I would need to keep track of state internally. E.g., if I have a tree like head a b/b /a a b/b /a /head and say I'm interested in all that's between b underneath any a, I'd need to have a state machine that looked for an a followed by a b. If I'm doing that, though, it seems like I should just start using a DOM parser instead? Yeah, I think you've got it nailed, although your example is simple enough (you're only holding one state value - am I a child of a?) that I'd probably still reflexively reach for the lightweight solution). I use SAX for lightweight hacks, one step up from regexes - I know the information I want is between tag and /tag, and I don't care about the rest of the document. The more I need to navigate the document, the more likely I am to use DOM. I could build my own data structures on top of a SAX parser, but why bother reinventing the wheel? Of course, you have to factor document size into that - parsing a big XML document into a tree can be slow. You might also want to explore XPath (http://uk.php.net/manual/en/function.simplexml-element-xpath.php http://uk.php.net/manual/en/class.domxpath.php)... XPath is to XML as Regexes are to text files. There's a good chance you'll be able to roll all your parsing up into a couple of XPath queries. I probably should have added that simple parsers come in two flavours - Push Parsers and Pull Parsers. I tend to think (lazily) of Push and Pull as variations on SAX, but strictly speaking they are different. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Good XML Parser
What's the best way to pull down XML from a URL? fopen($URL), then using xml_parse? Or should I be using XML_Parser or SimpleXML? Thanks, Waynn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Good XML Parser
So if I'm looking to parse certain attributes out of an XML tree, if I use SAX, it seems that I would need to keep track of state internally. E.g., if I have a tree like head a b/b /a a b/b /a /head and say I'm interested in all that's between b underneath any a, I'd need to have a state machine that looked for an a followed by a b. If I'm doing that, though, it seems like I should just start using a DOM parser instead? Thanks for any insight, Waynn On Mon, May 12, 2008 at 1:29 AM, David Otton [EMAIL PROTECTED] wrote: 2008/5/12 Waynn Lue [EMAIL PROTECTED]: What's the best way to pull down XML from a URL? fopen($URL), then using xml_parse? Or should I be using XML_Parser or SimpleXML? XML parsers fall into two general camps - DOM and SAX. DOM parsers represent an entire XML document as a tree, in-memory, when they are first instantiated. They are generally more memory-hungry and take longer to instantiate, but they can answer queries like what is the path to this node or give me the siblings of this node. SAX parsers are stream- or event-based, and are much more lightweight - they parse the XML in a JIT fashion, and can't answer much more than give me the next node. If you just need the data, a SAX parser will probably do everything you need. If you need the tree structure implicit in an XML document, use a DOM parser. Expat, which XML Parser (http://uk3.php.net/manual/en/book.xml.php) is based on, is a SAX parser. DOM XML (http://uk3.php.net/manual/en/book.domxml.php) is, obviously, a DOM parser. I don't know, off the top of my head, which camp SimpleXML falls into. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Apache child pid segfault + APD
My main problem with using xdebug was that it seemed to require KDE to interpret the traces that it took, which I don't have installed on my server. I only spent 15 minutes looking at it, though, so that could be completely unjustified... Would upgrading glibc help? On Sat, May 3, 2008 at 12:48 AM, Mario Guenterberg [EMAIL PROTECTED] wrote: On Fri, May 02, 2008 at 10:24:03PM -0700, Waynn Lue wrote: *** glibc detected *** free(): invalid pointer: 0x002a9956d000 *** Hi Waynn, try to use xdebug instead of APD to profile you app. There is a problem with your glibc version and your APD version. In my environment php 5.2.6 with suhosin/apc, apache 2.2.8 and xdebug 2.0.2 it works fine. Greetings Mario -- -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/CM d- s++: a+ C$ UBL*$ P++ L+++ E--- W+++ N+ o-- K- w O- M- V-- PS++ PE++ Y PGP+++ t--- 5 X R++ tv- b+++ DI D G++ e* h r+++ y --END GEEK CODE BLOCK-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Apache child pid segfault + APD
I recently installed APD to help profile some code that I've written, and noticed that whenever I run it (with apd_set_pprof_trace() at the top) I get these errors in my apache logs. I spent awhile looking at different sites, but even recompiling PHP + Apache didn't help. Anyone seen this before? [Fri May 02 21:20:56 2008] [notice] child pid 13818 exit signal Segmentation fault (11) [Fri May 02 21:40:08 2008] [notice] child pid 14820 exit signal Segmentation fault (11) [Fri May 02 21:40:08 2008] [notice] child pid 15027 exit signal Segmentation fault (11) [Fri May 02 22:00:08 2008] [notice] child pid 16081 exit signal Segmentation fault (11) *** glibc detected *** free(): invalid pointer: 0x002a9956d000 *** [Fri May 02 22:00:10 2008] [notice] child pid 15273 exit signal Aborted (6) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql query and maximum characters in sql statement
Wouldn't using LOAD DATA INFILE be better than writing your own script? On 5/1/08, Jim Lucas [EMAIL PROTECTED] wrote: Jim Lucas wrote: Sanjeev N wrote: Hi, I have written a program which imports the tab delimited file and insert all the line from file to the mysql line by line. I am succeding in the above case. but problem with the above method is its taking to too much time while inserting into the database. The file's size will be more than 5000 lines. Then i tried to build a string of ; seperated queries. as follows for($i=1; $isizeof($array); $i++){ $insert_string .= insert into tablename (v1, v2. v6) values('$array[$i][1]', '$array[$i][2]'. '$array[$i][6]');; } if(!empty($insert_string)){ mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } Its throwing error saying check the manual for right syntax. After investigating in some sites i come to know that its problem of limitations in query size. I also tried with SET GLOBAL max_allowed_packet=3000; Then also its throwing the same error. Can anybody tell me how to fix this error and reduce the inserting time with a single statement instead of writing more insert statements You are probably looking for something like this. ?php if ( count($array) ) { $insert_string = INSERT INTO tablename (v1, v2. v6) VALUES ; $data = array(); foreach ( $array AS $row ){ $row_clean = array_map('mysql_real_escape_string', $row); $data[] = ('{$row_clean[1]}', '{$row_clean[2]}',.'{$row_clean[6]}'); } $insert_string = join(', ', $data); mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } else { echo Nothing to insert; } ? That would work, but will probably result in a query string that is too long. I'll redo the above to fix that. ?php # How often do you want to insert?? $break_at = 100; # Initialize the counter $cnt = 0; # Initial insert string $insert_string = INSERT INTO tablename (v1, v2. v6) VALUES ; # if there is data, then process, otherwise skip it. if ( count($array) ) { $data = array(); # Loop through data foreach ( $array AS $row ) { $cnt++; # Clean the result data $row_clean = array_map('mysql_real_escape_string', $row); # Build data string and push it onto the data array. $data[] = ('{$row_clean[1]}', '{$row_clean[2]}',.'{$row_clean[6]}'); # Break and insert if we are at the break point if ( $cnt === $break_at ) { # Reset Counter $cnt = 0; # Run insert mysql_query($insert_string . join(', ', $data), $conn) or die(query failed : .mysql_error()); # Reset data array $data = array(); } //if } //foreach # This should take care of any extra that didn't get processed in the foreach if ( count($data) ) { # Insert remaining data mysql_query($insert_string . join(', ', $data), $conn) or die(query failed : .mysql_error()); } //if } else { echo Nothing to insert; } //if ? -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql_connect slowness
Our site has been slowing down dramatically in the last few days, so I've been trying to figure out why. I ran some profiling scripts on our site and saw that we're spending between 3-9 seconds on mysql_connect. Then I connected to our db and saw that there were over 100 connections at the time, most of them sleeping. Is this because we don't close mysql connections until the end of script execution? How do people generally structure their code to minimize the time they keep mysql connections open? Currently all db connections go through one file, which gets included at the top of the file. One other question, is it better to open one connection, then re-use it later, or just continually open and close per db call? Thanks, Waynn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Serialization Performance
Thanks very much, I ended up using seralize in the database. On Thu, Apr 17, 2008 at 4:42 AM, Casey [EMAIL PROTECTED] wrote: On Wed, Apr 16, 2008 at 4:04 AM, Waynn Lue [EMAIL PROTECTED] wrote: I'm using PHP to cache files that are backed by the database. In the course of writing these functions, I end up with a set of variables that are needed by my application, returned in an array. I can either directly generate the array in a .php file, then use require_once to get that variable, or I can use PHP serialization, write that array out to a file, then in my application read the array in, deserialize, etc. I spent awhile trying to look at the performance of php serialization, but except for one unsubstantiated comment on the php serialize() doc page, I haven't found much. Does anyone have any knowledge of that, and also of the two approaches in general? The pro of the serialization is that I think it's slightly easier to write, but the con is that it's harder to read. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php According to this (http://us2.php.net/manual/en/function.var-export.php#76099), serialize is faster than var_export. -- -Casey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Cannot modify header information - headers already sent by ...
I fixed this last time by looking for white space both before and after the opening and closing php tags, as a Google search had revealed. But this time, I've spent an hour running down various files and not seeing what the heck is wrong. Here's the essential setup. main.php ? require_once 'shared_style.php'; require_once 'something.php' ? shared_style.php style a.friend_selector_tabs:hover { background: #E4E4F8 none repeat scroll 0%; } .title_msg { font-size: 14px; color: #44; font-weight:bold; } /style The something.php has a setcookie call on the line number that PHP is complaining about for headers. What am I doing wrong that's causing even mire headers to be generated? I tried moving the require_once 'something.php' above, but no luck there either. Thanks for any help, Waynn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cannot modify header information - headers already sent by ...
This is for a facebook app, so it's just public function set_user($user, $session_key, $expires=null) { if (!$this-in_fb_canvas() (!isset($_COOKIE[$this-api_key . '_user']) || $_COOKIE[$this-api_key . '_user'] != $user)) { $cookies = array(); $cookies['user'] = $user; $cookies['session_key'] = $session_key; $sig = self::generate_sig($cookies, $this-secret); foreach ($cookies as $name = $val) { setcookie($this-api_key . '_' . $name, $val, (int)$expires); $_COOKIE[$this-api_key . '_' . $name] = $val; } setcookie($this-api_key, $sig, (int)$expires); $_COOKIE[$this-api_key] = $sig; } $this-user = $user; $this-api_client-session_key = $session_key; } But the problem is I can't tell where it's being called. Is there any way to generate a stack trace from the error logs so I know what the calling function is? On Mon, Apr 21, 2008 at 4:37 PM, Daniel Brown [EMAIL PROTECTED] wrote: On Mon, Apr 21, 2008 at 11:33 AM, Waynn Lue [EMAIL PROTECTED] wrote: I fixed this last time by looking for white space both before and after the opening and closing php tags, as a Google search had revealed. But this time, I've spent an hour running down various files and not seeing what the heck is wrong. Here's the essential setup. main.php ? require_once 'shared_style.php'; require_once 'something.php' ? If something.php is setting cookies and such, it has to be above shared_style.php. If you've already tried that with no success, post the code of something.php for us to view. -- /Daniel P. Brown Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cannot modify header information - headers already sent by ...
Actually, I think I fixed it by moving the style sheets below the instantiation of the facebook client, where I *think* set_user was being called. I'm still curious if it's possible to get stack trace information on errors, though. :) Waynn On Mon, Apr 21, 2008 at 5:39 PM, Waynn Lue [EMAIL PROTECTED] wrote: This is for a facebook app, so it's just public function set_user($user, $session_key, $expires=null) { if (!$this-in_fb_canvas() (!isset($_COOKIE[$this-api_key . '_user']) || $_COOKIE[$this-api_key . '_user'] != $user)) { $cookies = array(); $cookies['user'] = $user; $cookies['session_key'] = $session_key; $sig = self::generate_sig($cookies, $this-secret); foreach ($cookies as $name = $val) { setcookie($this-api_key . '_' . $name, $val, (int)$expires); $_COOKIE[$this-api_key . '_' . $name] = $val; } setcookie($this-api_key, $sig, (int)$expires); $_COOKIE[$this-api_key] = $sig; } $this-user = $user; $this-api_client-session_key = $session_key; } But the problem is I can't tell where it's being called. Is there any way to generate a stack trace from the error logs so I know what the calling function is? On Mon, Apr 21, 2008 at 4:37 PM, Daniel Brown [EMAIL PROTECTED] wrote: On Mon, Apr 21, 2008 at 11:33 AM, Waynn Lue [EMAIL PROTECTED] wrote: I fixed this last time by looking for white space both before and after the opening and closing php tags, as a Google search had revealed. But this time, I've spent an hour running down various files and not seeing what the heck is wrong. Here's the essential setup. main.php ? require_once 'shared_style.php'; require_once 'something.php' ? If something.php is setting cookies and such, it has to be above shared_style.php. If you've already tried that with no success, post the code of something.php for us to view. -- /Daniel P. Brown Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP Serialization Performance
I'm using PHP to cache files that are backed by the database. In the course of writing these functions, I end up with a set of variables that are needed by my application, returned in an array. I can either directly generate the array in a .php file, then use require_once to get that variable, or I can use PHP serialization, write that array out to a file, then in my application read the array in, deserialize, etc. I spent awhile trying to look at the performance of php serialization, but except for one unsubstantiated comment on the php serialize() doc page, I haven't found much. Does anyone have any knowledge of that, and also of the two approaches in general? The pro of the serialization is that I think it's slightly easier to write, but the con is that it's harder to read. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php