-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
You need to include the --with-apxs2 when compiling PHP to build it as an apache module. apt-get'ing that lib is going to present the same issues you had when you tried to apt-get php5-mysql. Your using ubuntu's version which may be incompatible with your custom-compiled stuff.
-
You can just create a separate form for each button with a hidden input. Eg: foreach ($Cars as $car){ echo '<form action="content/QuickSearch.php" method="post">'; echo '<input type="hidden" value="'.$car['id'].'" name="n">'; echo '<input type="submit" value="Reserve">'; echo '</form>'; }
-
Accessing the value of a Multidimensional array
kicken replied to sakilimran's topic in PHP Coding Help
echo $price_list[$height][$width]; You use the $height variable as the first key value (140) and $width as the second key value (396). You may get E_NOTICE messages if there is no match for your width/height combo, eg if you had $width=100, $height=100. You could solve that with some isset checks prior to trying to access the value. -
Trying to apt-get php5-mysql is going to cause apt to include the mysql client libraries. Ubuntu's version of these libraries likely conflict with your self-compiled version and are going to cause you all sorts of problems. Things like this is why compiling stuff your self and using apt-get don't mix well, especially if there is a dependency involved between your self-compiled stuff and the package-managed stuff. You could probably either compile PHP yourself as well, or just go with the apt-get version of mysql so everything matches up.
-
Browser Caching dynamic content using PHP output buffer and ETag
kicken replied to mikerowe81's topic in Application Design
Depends on what kind of content it is you're serving up on what kind of caching you might do. If you can reliably determine a last modified date, then do that. For example if you were serving up blog posts you might update the timestamp any time the blog is modified. In such a case, you can use that to generate a Last-Modified header to send with the page. When a url is requested you could check for a $_SERVER['HTTP_IF_MODIFIED_SINCE'] header and do a quick check before actually rendering the blog post out. Eg: <?php if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ $lastModified = queryDbForLastModifiedDateOnly(); if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModified){ header('HTTP/1.1 304 Not Modified'); exit; } } $blogData = queryDbForBlogData(); header('Last-modified: '.$blogData['lastModifiedDate']) //Lookup the proper date format. echo $blogData['contents']; exit; For an etag approach you could do a hash of the contents of the page or some set of data that you need to know if it's changed or not. In the blog example above rather than checking a last modified time you could just hash the $blogData['contents'] and use that as an etag. The potential problems to something like this comes from if you change the sites layout but not any of the content. The cache check wouldn't recognize that since it only checks the content. You could get around that by having an indicator of the last time the layout has changed, such as maybe a layout version # or last changed date that you include in in the cache check. Eg: define('LAYOUT_VERSION', '1.0'); //In a global config file somewhere $etag = crc32(LAYOUT_VERSION.$content); //to generate the tag Changing either the content or the version would cause the etag value to change.- 3 replies
-
- caching
- output buffer
-
(and 2 more)
Tagged with:
-
Improving efficiency on a time-consuming Cron job
kicken replied to RealityRipple's topic in Application Design
Yea, add the unlink after your call to execute(). The script will be looping within that method until all the requests are complete. Once it finishes it should be ok to remove the file and do any other post-processing you might want to do. -
Quick rundown of the modifiers: public means the member is visible to all scopes of the current class or any sub-classes of it. protected means the member is visible to only the class scope of the current class or any sub-classes of it. private means the member is visible to only the class scope of the current class. By class scope I mean from within the class definition code. Ie: class ABC { protected function myMethod(){ echo 'Hello'; } public function someOtherMethod(){ $this->myMethod(); //You can access the method here. echo ' World!'; } } $a = new ABC(); $a->myMethod(); //But not here $a->someOtherMethod(); //It can be called indirectly through a public method.
-
Improving efficiency on a time-consuming Cron job
kicken replied to RealityRipple's topic in Application Design
That won't be the case if you add the request during the processing callback function. After rolling cURL calls your function, it checks if there are any pending requests yet to be processed (which will include the one(s) you just added during the callback). If there are remaining requests to be processed it will add it to curl multi process and it will begin processing that request immediately. The only potential issue I see is if you start out with just a single request, as in that instance it skips the curl multi stuff and just does a single execution. In that scenario any requests added after the initial call to execute() would be skipped. -
Don't try and use two different versions of jQuery. Pick one and stick with it. I'd suggest using the newest version. If you have some old code that doesn't work under the newest jQuery, look into updating that code to be compatible.
-
Improving efficiency on a time-consuming Cron job
kicken replied to RealityRipple's topic in Application Design
I've never personally used rolling cURL or cURL multi before. Last time I did anything in parallel I rolled my own due to now knowing about them, and have not had to do anything like that since learning of them. Based on the readme for rolling curl however, something like the below should be the setup you're after: <?php class MyRequest extends RollingCurlRequest { private $mType; private $mRc; const TYPE1=1; const TYPE2=2; public function __construct($url, $type, $rc){ $this->mType = $type; $this->mRc = $rc; parent::__construct($url); } public function ProcessResponse($responseBody, $responseInfo){ switch ($this->mType){ case self::TYPE1: $this->ProcessType1($responseBody, $responseInfo); break; case self::TYPE2: $this->ProcessType2($responseBody, $responseInfo); break; } } private function ProcessType1($body, $info){ //blah blah blah } private function ProcessType2($body, $info){ //blah blah blah } } $rc = new RollingCurl(function($response, $info, $request){ $request->ProcessResponse($response, $info); }); foreach ($Emails as $email){ $type = //determine type of initial request $url = //determine URL of initial request $req = new MyRequest($url, $type, $rc); $rc->add($req); } $rc->execute(); You setup all your initial type1 or type2 requests by adding them to the rolling curl object. As each one completes it will call the callback function, which you then have call your processing function. If during the processing function you determine that you need to issue another request, you can just add it to the queue by creating a new request object and adding to the queue by calling the add method again. Eg: $req = new MyRequest($newUrl, $this->mType, $this->mRc); $this->mRc->add($req); -
Sort an array of keys based on their values, then after that array of keys is sorted, grab the original values for each key. Untested, but rough idea: $keys = array_keys($arr); for ($i=0; $i<count($keys); $i++){ for ($n=0; $n<$count($keys); $n++){ $a = $arr[$keys[$i]]; $b = $arr[$keys[$n]]; if ($a < $B){ $tmp=$keys[$n]; $keys[$n] = $keys[$i]; $keys[$i] = $tmp; } } } $final = array(); foreach ($keys as $key){ $final[$key]=$arr[$key]; } print_r($final);
-
I don't limit passwords at all aside from minimum length/complexity limits. Let a user enter whatever characters they want for however long they want to. Once you hash the password with your algorithm of choice it doesn't really matter what their original input was. As for the complexity rule you want (one upper, lower, and numeric) do three separate simple tests rather than trying to come up with a complex regex: $pass = 'This is my pa55w0rd!'; $valid = preg_match('/[A-Z]/', $pass) && preg_match('/[a-z]/', $pass) && preg_match('/[0-9]/', $pass)
-
disable_functions doesn't work?
kicken replied to kenw232's topic in PHP Installation and Configuration
-
The diference between tinyint(4) and tinyint(3)?
kicken replied to milanello72's topic in MySQL Help
For integer types (tinyint, smallint, int, etc) the number in parenthesis is the display width that is used when the column is created with the ZEROFILL property. If the number stored is less than the display width, it is zero-padded up to that width. Eg: For example, a SMALLINT(4) ZEROFILL would return the number 125 as '0125' in SELECT queries. The number 12050 however would still be returned as '12050'. It is already larger than the display width so no padding is done. -
open_basedir does not apply to shell_exec backticks?
kicken replied to kenw232's topic in PHP Installation and Configuration
open_basedir is a PHP setting, and as such only has an effect on PHP's functions. When you run an external program that program is not subject to the same limitations as PHP is. -
You have to fetch all the results from your first query before you can run your second query, otherwise you'll get an error regarding commands out of sync. eg: $sql = "select ..."; $stmt = $db->prepare($sql); $stmt->exec(); $results = $stmt->fetchAll(); $sql = "select found_rows()"; $stmt = $db->query($sql); $rows = $stmt->fetchColumn(0); $stmt->closeCursor();
-
Use && for a logical-and, not 'and'. 'and' has low precedence so it is evaluated last. In other words, your code runs as if it were written like: $tmp = $write==0 ? "auto" : "hidden"; $tmp = isset($ad) and $tmp; echo $tmp;
-
Improving efficiency on a time-consuming Cron job
kicken replied to RealityRipple's topic in Application Design
There is a library called rolling-curl you could check into that may simplify the process for you. The idea with curl multi exec though is that you'd setup your list of URL's that you need to download and then enter a loop. curl will attempt to download them all in parallel and once one of the URL's has finished downloading you can run it through whatever processing function you need. This is just pseudo-code, but the process essentially looks something like this: addUrlsToList(); while (urlsToDownload() > 0){ doDownload(); //curl will try and retrieve data from any of the urls in the list if (urlIsFinished()){ processUrlData(); } } Like I said that's just pseudo-code to illustrate the process, the way you actually go about setting it up is a bit more complex, but the library should help with that. -
Improving efficiency on a time-consuming Cron job
kicken replied to RealityRipple's topic in Application Design
You can run multiple downloads at the same time without having to involve multiple processes. For example, curl_multi_exec to download several things at once using curl. There are other ways but curl is probably the easiest and is generally supported. -
Improving efficiency on a time-consuming Cron job
kicken replied to RealityRipple's topic in Application Design
The first thing you should probably do is profile your cron script and try and identify any areas that are running slow. You may be able to speed it up using alternative algorithms / functions. If you want, post the script(s) here and someone could look at them for you. As far as trying to do some type of threading, if 1and1 offers pcntl you can use pcntl_fork to spawn new processes from the main script. If it doesn't offer that extension but allows you to use exec you can spawn a new PHP process and put it into the background by adding >/dev/null 2>&1 & to the end of the command line. However, I would try the profiling first to make sure you have the script running as efficiently as possible. Spawning off new processes will not necessarily run any faster as you're still doing the same amount of work. You'd only see an improvement through multiple processes if the server is not busy doing other tasks and can spare other CPU cores to run the processes in parallel. For a shared host, there might not be much for spare cpu cycles between all the other sites/scripts trying to run so you'd see little to no improvement in such a case. -
Did you install the Microsoft SQL Server 2012 Native Client? You need that for the driver to work properly. You can download it from http://www.microsoft.com/en-us/download/details.aspx?id=29065
-
Wasted an hour or so yesterday on this. Apparently max_input_vars doesn't work as advertised. Rather than being a limit on a single array dimension it is a grand total limit (https://bugs.php.net/bug.php?id=62921). It was my understanding that this directive was put into place because of how PHP manages arrays. As the array gets larger accessing it gets slower so they added this to prevent attacks by people posting large arrays. Oh well, worked around it in my case, but felt like bitching a little bit.
-
For something like a photo gallery viewing the original image is one of the options people have. I code my gallery to show a grid of thumbnails, clicking a thumbnail opens a medium version (eg, 800x600) and clicking that will open the original image. For such a thing you'd have to store the original image anyway as part of the functionality of the script. If for some reason it is something that doesn't need the original as part of it's use, I'd still store it anyway probably. That way you can re-generate the thumbnail if need be. As mentioned, you could reduce the image some if it's gigantic, like maybe only store a max of 1280x1024 or similar.
-
Load the url contents using cURL or file_get_contents into first, then create the domdocument and populate it using the loadHTML() method.
-
Small modification of Barand's: function validReg($plate) { $arr = explode('-', $plate); if (count($arr) != 3) return false; foreach ($arr as $pairNum=>$pair) { if (strlen($pair) != 2) return false; else if (($pairNum%2)==1){ if (!ctype_alnum($pair)) return false; } else if (!ctype_alpha($pair) && !ctype_digit($pair)) return false; } return true; } The way I read the instructions, the first and last group have to be either both letter or both digits. The center group however can be a mix. This also incorporates the modulus operator to identify the center group. eg, AB-1C-EF A letter is always next to another letter or next to a '-' character. C- A digit always stands next to another digit or next to a '-' character. -1