Re: [PHP] Selecting a special row from the database
Edward Kay a écrit : -Original Message- From: Fredrik Thunberg [mailto:[EMAIL PROTECTED] Sent: 04 May 2007 15:31 To: Edward Kay Cc: php-general@lists.php.net Subject: Re: [PHP] Selecting a special row from the database Edward Kay skrev: -Original Message- From: Marcelo Wolfgang [mailto:[EMAIL PROTECTED] Sent: 04 May 2007 14:37 To: php-general@lists.php.net Subject: [PHP] Selecting a special row from the database Hi all, I'm building a news display page for a website, and since the user has 2 ways to arrive there, I want to know if this is possible: 1) the user arrive at news.php I will run a query at the db, and get the latest news to be the main one (full display) and display the others news in a list 2) the user arrived from a link to a specific news to news.php?id=10 It should display the news with id = 10 as the main news and get the latest ones to display in a list of other news I've so far was able to add a dinamic WHERE to my query ( if I have or not the id GET parameter ) and if I don't have it, I'm able to display the latest result as the main news, but when I have an id as a GET parameter, I have a where clause in my query and it will return only the main news and not build up the news list what I want is to separate the news that the user want to see ( the id=XX one ) from the others rows, can someone advice me ? Here is the code I have so far, I hope it serve as a better explanation than mine! TIA Marcelo Wolfgang If id is set, query the DB for this news article and put as the first element in an array. Then perform a second query WHERE ID != id and append the results to the array. If id isn't set, just perform the one query without any where clause. If you want to do it all in one query, if id is provided use SELECT... WHERE ID = id UNION (SELECT...WHERE ID != id ORDER BY id DESC) to get the ordering you want. If id isn't set just use SELECT ... ORDER BY id DESC. I'm not sure if there would be much difference in performance as I still think the database would perform two queries internally. Edward Maybe SELECT ..., if (id = my_id,1,0) as foo ... ORDER BY foo DESC; Good idea! Just tried it out and it works really well. Hello, If you're looking for performance, why do you select everything for articles that are not in full display ? Isn't it better if you SELECT * just for the article you want in full display and make another query for other titles ? LIMIT would also help performance. Cheers -- Emmanuel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Send binary files with gzip encoding disabled
strawks a écrit : Hello, I'm trying to send a ZIP file generated on the fly in a temporary directory. The ZIP file is created successfully and I'm using the following code to send it to the client : $filesize=filesize($path); $mimetype='application/zip'; // Make sure there's not anything else left ob_clean_all(); // Start sending headers header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Transfer-Encoding: binary"); header("Content-Description: File Transfer"); header("Content-Type: ".$mimetype); header("Content-Disposition: attachment; filename=\"".$name."\";" ); header("Content-Length: ".$filesize); [EMAIL PROTECTED]($path,"rb"); while([EMAIL PROTECTED]($fp)) { set_time_limit(0); print @fread($fp, 8192); } @fclose($fp); The ob_clean_all() function : function ob_clean_all () { $ob_active = ob_get_length () !== false; while($ob_active) { ob_end_clean(); $ob_active = ob_get_length () !== false; } return true; } The problem is that Apache process the output throught gzip and so drop the Content-Length header replacing it with a chunked transfer. This should work fine but Internet Explorer simply save the raw gzip compressed data instead of the ZIP archive. However this works fine with Firefox. gzip encoding is unecessary since I'm transfering a ZIP archive, so I think just disabling it should solve the problem, but I haven't found how to do this. Any help would be appreciated. Hello, I have about the same code except that I use "application/x-zip-archive" for the content type and it just works. There's no ob_* stuff in my code also. 'hope that helps you out... -- Emmanuel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Problem with timeout
Frank Arensmeier a écrit : Hello. I am currently working on a script that parses a given http adress by looking for anchor tags, background images and so on - a crawler if you like. The downloaded content is temporarily stored on the server (Mac OS X Server 10.4.9 with PHP 5) and, when the script is done, the content is packed into a ZIP archive. It seems that I am having trouble with my Apache timeout setting. Because the script downloads between 250 and 300MB of html, pdf, css files and so on, it is terminated automatically after the specified timeout setting (currently 1200 seconds). Setting max execution time to -1 in the script has no effect (which has been noticed previously on the php.net manual page). Is there any other way (with PHP) to come around this problem besides setting the time-out in the Apache config to more than 1200 seconds? The Apache manual says that the time out value can only be changed within the core configuration scope. My initial idea was to set the value in a .htaccess file which unfortunately is not allowed. I might also add that the script is already optimized for speed so to say. Hope you get what I mean. //frank Hello Frank Are you really sure you need an Apache-spawned PHP script to do all that long stuff ? Even if Apache does not give up on your PHP script, the HTTP client might do so. This is also not a good idea for a site with several clients because Apache could easily run low on available sockets, causing a DoS. I suggest you just spawn a background process from your PHP script, through some shell command like batch and nohup. The background process can still be coded in PHP with the CLI interface. At the end of the long process, you alert the user job was done (e.g. by mail or by some kind of AJAX mechanism) and let him download the result. In the Apache-spawned script: In long_process.php: You may need to give the right to www-data, or whatever account running Apache, to create jobs through at/batch. Regards -- Emmanuel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] cURL: multipart/form-data POST request with empty file part
Hello I'm writting a client in PHP for some CMS. I need to send an HTTP POST request with a multipart/form-data content. One of the parts is a file which must look like the request was issued after submitting a web form with a field left empty, which is *NOT* the same as sending an empty file. This means the part should look like this in the request: -8179530329826\r\n Content-Disposition: form-data; name="file"; filename=""\r\n Content-Type: application/octet-stream\r\n \r\n \r\n -8179530329826\r\n Is there a way to do so with cURL ? Thanks in advance -- Emmanuel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php