nik_jain
Members-
Posts
60 -
Joined
-
Last visited
-
Days Won
1
Everything posted by nik_jain
-
I see.. So I guess another way of saying what I want to ask is 'how to detect the BASE_URL automatically ?' If memory serves right then some frameworks do try to detect the base URL automatically while also giving an option to set it manually. ok googling around I found this: http://blog.lavoie.sl/2013/02/php-document-root-path-and-url-detection.html But I think the following way should also work, with any router. I don't see any gotchas in this, but there might be. $base = dirname($_SERVER['PHP_SELF']) ; if ($base === '/' || $base === '\\'){ $base = '' ; } $klein = new \Klein\Klein(); $klein->respond('GET', $base.'/hello', function () { return 'Hello World!'; }); $klein->dispatch();
-
->with() works nicely! Thanks $base = dirname($_SERVER['PHP_SELF']) ; if ($base === '/' || $base === '\\'){ $base = '' ; } $klein = new \Klein\Klein(); $klein->with($base, function() use($klein) { $klein->respond('GET', '/hello', function () { return 'Hello World!'; }); }); $klein->dispatch(); by hardcoding into .htaccess ? I kind of wanted a 'redistributable' solution..
-
I was trying to use one of the many PHP routers like klein, when I kept hitting an issue. The issue was my root folder was a subdirectory of the www folder . So instead of requesting http://localhost/index.php (as one would if the index.php was located in /var/www) I was requesting http://localhost/issues/web/index.php (index.php in /var/www/issues/web) Naturally the router looked for a match for the whole path(issues/web/index.php) instead of just the relative path(/index.php) Which caused it not to match anything ! Questions: 1. Is this a viable solution for this problem (Got this from https://github.com/chriso/klein.php/wiki/Sub-Directory-Installation? Any possible gotchas I should be on the look out for ? $base = dirname($_SERVER['PHP_SELF']); // Update request when we have a subdirectory if(ltrim($base, '/')){ $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], strlen($base)); } //initialize router code. 2. This must be an extremely common situation! How do people deal with this ? OR is it simply not common for routers to be installed to subfolders and called from there ? Thanks
-
Its like an elusive goal of mine. To be able to write big pieces of code that are reusable in multiple projects. For example: Lets say we are coding a simple 'Membership system'- login / signup etc. How would for instance something like routing would be handled in this so that it remains modular. Reusable in multiple projects that may be using a different router for their projects. Any guidance please ? Is there a book that shows how its done ?
-
You could try replacing \n by \r\n as the line separator. As thats what the csv contains.
-
Dude xpath and DOM are a pain! Try the library Querypath (its a wrapper around DOMDocument). It takes the pain out of these things.
-
Automatically Navigating A Website (that is not my own)
nik_jain replied to gerkintrigg's topic in Applications
The PHP way would be to use cURL and send a POST request . But for something simpler , something that can record and replay your actions, you can try the imacros extension for firefox. -
I have spent the last few days going over Zend framework 2, and I am finding it extremely complex. Not saying it shouldn't be, but it seems to solve problems I never have come across (so to speak) . For instance: Routing is super complex. I usually use torophp - which is simple & gets the job done. Dependency injection - example of problem I have never come across. My motivations for learning zend, are - 1. To write modular reuseable code. 2. Learn advanced / modern PHP , as far as frameworks are concerned I just know codeigniter. 3. A framework with good long term support. Is there some other framework that is easier to learn ? and that would satisfy my requirements ? I have been programming in PHP for the last 2-3 years btw, so I know my way around Thanks
-
I think it should be - var_dump(json_decode($response->GetProspectAsJSONResult, true));
-
Mysqli query in a loop takes longer with each iteration. why?
nik_jain replied to nik_jain's topic in PHP Coding Help
I figured it out! The problem was in this query. Mysqli doesn't like large offsets in large tables. So the solution was to simply add a WHERE product_id > ($offset value) and remove the OFFSET Now the part that at minimum took .06, takes only .005 Ah thanks for this, I haven't extensively used prepared statements. This was just an attempt to find the culprit. -
In the above loop the time taken by the call to get_rows_from_ppt($start, $atOnce); gradually (but slowly) increases over each iteration. When the loop starts it takes about .06 sec to execute, but after several thosand iterations the time taken by the same function is .2 seconds. If I let the script continue running, then it increases to .6 seconds. Why ? Here are the other 2 functions being called above: Edit: I forgot to mention the table is of the form : +------------+---------------------+-------+ | product_id | insertion_timestamp | price | +------------+---------------------+-------+ | 1123 | 1406719422 | 7323 | | 1123 | 1407313884 | 7323 | | 1123 | 1408284527 | 7323 | | 1123 | 1408381296 | 7323 | | 1124 | 1406719422 | 1831 | | 1124 | 1407313884 | 1831 | | 1124 | 1408284527 | 1831 | | 1124 | 1408381296 | 1831 | having a index on product_id
-
This link http://www.pokerhaze.com/blog/az.php is throwing a "500 internal server error" What are the permissions on the blog folder ? Try matching them to the httpdocs folder (just a guess) Also try commenting out the includes one by one to see what is causing the internal server error.
-
I FIGURED IT OUT!! I stumbled upon this article: http://php.net/manual/en/mysqlinfo.concepts.buffering.php , which was exactly what I needed. Basically when the $pricetimes resultset is created, I had to make sure to use MYSQLI_USE_RESULT (for unbuffered mode in mysqli). This made the fetch_assoc() NOT keep the results in memory and keeps the memory use down to 50MB or so. The downside of this is that one cannot data_seek or get a count of the rows. But as I didn't require either this solution is perfect!
-
In the following code the memory usage balloons up to 500MB while ($priceRow = $pricestimes->fetch_assoc()) { //if another product if ($last_product_id != $priceRow['product_id']){ // 100 products together if ($count % 100 == 0) { echo 'MEM AFTER 100 products- ' . (memory_get_usage(true) / 1024 ). PHP_EOL; //add_price_array_to_db($pricesArr) ; $pricesArr = array(); } $count++; $last_product_id = $priceRow['product_id'] ; } $pricesArr[$priceRow['product_id']][$priceRow['insertion_timestamp']] = $priceRow['price']; } The 'echo MEM AFTER 100 products-' line shows that the memory of the script keeps on increasing. Any ideas why there is a memory leak here ? The $pricestimes is a huge mysqli resultset with 23 million rows, so I suspect that may be the issue here. Unless there is something wrong with the script logic. btw the 'add_price_array_to_db($pricesArr)' is uncommented in the real code. But even with this line commented out the memory leak is there. Thanks
-
You are looking for regex / preg_match . Alternatively you can use the library Querypath , but querypath may be an overkill for this.
-
You could try : 1. searching for die|exit in the whole project, just in case there isn't any of those lying about somewhere. 2. ensure set_time_limit is set to 0 3. http://php.net/manual/en/function.register-shutdown-function.php
-
If I understand the problem correctly, then changing the forloop to: for ($i = 1 ; $i <= $countImages; $i++) { should help The issue being that - 0 % $any_number is always equal to 0 . If we start counting from 1 instead of zero, then we can avoid this effect.
-
what does print_r ($images) show ? Is the missing image even there in the array ?